Skip to content
Advertisement

sql join values from same table

i came up by visiting this question.

so i made a query like this

And Database is like this enter image description here So basically my need is i need an refUserId User Full Name When i am querying like

Above Query Result output me same name as the userName enter image description here

Advertisement

Answer

You are probably looking for an outer join: Show all users along with their ref user, if such exists.

I’ve corrected the erroneous join condition (wrong ID). Moreover, as there exists no user with user ID 0, and I guess you just meant to avoid looking that ID up, I dropped the condition ru.iRefUserId > 0. It is not needed, because the outer join handles this already.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement