Furqan Ansari Furqan Ansari -4 years ago 71
MySQL Question

how to get two column keys from one table

table 1

id name
1 Av1
2 Av2

table 2

id name1 name2
1 1 2

I want name according to table1.id like,


id name1 name2
1 Av1 Av2

Answer Source

You need to join table1 twice, e.g.:

SELECT t2.id, t1.name, t11.name
FROM table2 t2 JOIN table1 t1 ON t2.name1 t1.id
JOIN table1 t11 ON t2.name2 = t11.id
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download