How to select a value from a column that is based on another row and column value?

advertisements

Well, best explained with a example:

MYSQL TABLE NAME: CLIENTS
ID        NAME        CODE
1         Mark        0
2         Joe         1

What I want:

HTML TABLE:
MATCH        NAME
Mark         Joe

Did you get it? Like, i need to take the NAME from the person who has a ID equal to the CODE of other.

I think that you won't need my code, since I just want to know the function that allows me to echo two distinct "NAMES". Like, if I call two echo $name; how the code knows who is who?

Ps.: I'm not a back-end developer, take it easy =)
Ps².: It is a loop (what I know to do hehehehe), it has to repeat that "search" and list a lot of "MATCHES", you know?


we can find reord in the same table by using self join...

SELECT e.NAME as parent, m.NAME as child FROM CLIENTS e, CLIENTS m WHERE e.ID = m.CODE

Hope this will be your solution