Thread: JOIN query
View Single Post
Old 11-25-2010, 07:09 AM   #3 (permalink)
maeltar
The Acquainted
 
Join Date: Nov 2009
Location: nr Stratford-Upon-Avon
Posts: 137
Thanks: 3
maeltar is on a distinguished road
Default

something like

(The associated record was userid)

Code:
select * from table1 left join table2 on table1.userid = table2.userid


+--------+-----------+-------+--------+--------+
| userid | name      | imgid | img    | userid |
+--------+-----------+-------+--------+--------+
|      1 | Mr Smith  |     3 | image3 |      1 |
|      2 | Mr Jones  |     1 | image1 |      2 |
|      2 | Mr Jones  |     2 | image2 |      2 |
|      3 | Mrs Jones |  NULL | NULL   |   NULL |
|      4 | Mr Patel  |     4 | image4 |      4 |
|      4 | Mr Patel  |     5 | image5 |      4 |
+--------+-----------+-------+--------+--------+
Another option is :

Code:
 select * from table1, table2 where table1.userid = table2.userid;
+--------+----------+-------+--------+--------+
| userid | name     | imgid | img    | userid |
+--------+----------+-------+--------+--------+
|      1 | Mr Smith |     3 | image3 |      1 |
|      2 | Mr Jones |     1 | image1 |      2 |
|      2 | Mr Jones |     2 | image2 |      2 |
|      4 | Mr Patel |     4 | image4 |      4 |
|      4 | Mr Patel |     5 | image5 |      4 |
+--------+----------+-------+--------+--------+
__________________
Thanks... Simon

Sex, Drugs & Linux Rules
Send a message via MSN to maeltar
maeltar is offline  
Reply With Quote