Query two columns that reference each other, how to?

Surister :

r

So Having this table, how would I go to get

Code is PK

the name and next to it, the name of the boss, I have no idea how would I get the name out of the boss code?

Caio Oliveira :

You have there a self relation.

You just have to think about it as it was another table.

Just use a join (left or inner, depends what you need)

SELECT e.code, e.name, b.code, b.name from table_name e
join table_name b on e.boss = b.code

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=170064&siteId=1