Reputation: 1
I have a table that looks like this:
Persons:
+---------+----------+----------+
| ID | name | clientID |
+---------+----------+----------+
|001 | carl |002 |
|002 | fred |null |
+---------+----------+----------+
I want the result to be:
+---------+----------+
| name | client |
+---------+----------+
|carl | fred |
+---------+----------+
I can get the output of people with clients with that clients ID (with the following) but not sure how to get the clients name to replace it.
select name, client
from schema.persons
where client is not null
thanks in advance.
Upvotes: 0
Views: 35
Reputation: 231651
You can implement a self join
SELECT p.name,
c.name as client
FROM schema.persons p
JOIN schema.persons c
ON( p.clientID = c.id )
Upvotes: 4