Skip to content

Instantly share code, notes, and snippets.

@discoposse
Created February 3, 2014 20:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save discoposse/8791513 to your computer and use it in GitHub Desktop.
Save discoposse/8791513 to your computer and use it in GitHub Desktop.
Is this a subquery I need?
people table fields:
id,first_name,last_name,login,manager_id
I need to get all the info, plus the login of the manager where manager_id references the record in the people table.
This is why I'm not a DBA
@bitzbyte
Copy link

bitzbyte commented Feb 4, 2014

I'd use a JOIN:

SELECT L.first_name, L.last_name, L.login, R.login
    FROM Table AS L
    LEFT OUTER JOIN Table AS R ON (L.manager_id = R.id)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment