Skip to content
Advertisement

MySQL: gets the id instead of the value

I have two tables in my database. Men table:

+----------------------------------------
| ID | menname              | partner   |
+----------------------------------------
| 1  | Mark                 | 1         |
| 2  | Adam                 | 2         |
----------------------------------------+

Women table:

+---------------------------------------+
| ID | womenname                        |
+---------------------------------------+
| 1  | Lisa                             |
| 2  | Emma                             |
+---------------------------------------+

When I do a inner join, I get:

+----------------------------------------
| ID | menname              | partner   |
+----------------------------------------
| 1  | Mark                 | 1         |
| 2  | Adam                 | 2         |
----------------------------------------+

instead of:

+----------------------------------------
| ID | menname              | partner   |
+----------------------------------------
| 1  | Mark                 | Lisa      |
| 2  | Adam                 | Emma      |
----------------------------------------+

It gets the id, instead of the partner name. Anyone know what is wrong with my query?

Advertisement

Answer

SELECT  m.ID
        ,m.menname
        ,w.womenname AS partner
FROM    Men AS m
        INNER JOIN Women AS w ON m.partner = w.ID;
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement