MySQL Forums
Forum List  »  MySQL Query Browser

joining tables with differnt row quantities
Posted by: Jilco Tigchelaar
Date: October 04, 2011 12:11PM

I have a problem with joining 2 tables with different quantity of rows, i tried LEFT JOIN but i does not work and i suppose that’s because of the ID_advertentie. Query:
SELECT * FROM table1
LEFT JOIN table2 ON table1.ID_kenmerk = table2.ID_kenmerk
WHERE table1.categorie = 1 AND table2.ID_ advertentie = 17

How can i write one query with the outcome mentioned as below the table examples?


Table 1
ID_kenmerk Categorie Naam_kenmerk Plaatje_kenmerk Data_type
1 - 1 - Kenmerk a - plaatje1.gif - INT
2 - 1 - Kenmerk b - plaatje2.gif - BOOL
3 - 1 - Kenmerk c - Plaatje3.jpg - INT
4 - 1 - Kenmerk d - plaatje4.jpg - VARCHAR
5 - 2 - Kenmerk F - plaatje1.gif - INT
6 - 2 - Kenmerk G - plaartje2.gif - VARCHAR

Table 2
ID_kenmerk_data ID_kenmerk ID_advertentie value
1 - 1 - 17 - Test1
2 - 2 - 17 - Test2
3 - 3 - 17 - Test3
4 - 1 - 23 - lala1
5 - 2 - 23 - lala2
6 - 3 - 23 - ajdk2

Outcome query (WHERE ID_advertentie = 17!)
ID_kenmerk Naam_kenmerk value
1 - Kenmerk a - Test1
2 - Kenmerk b - Test2
3 - Kenmerk c - Test3
4 - Kenmerk d - NULL



Edited 1 time(s). Last edit at 10/04/2011 10:15AM by Jilco Tigchelaar.

Options: ReplyQuote


Subject
Written By
Posted
joining tables with differnt row quantities
October 04, 2011 12:11PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.