SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
-
Dec 30, 2008, 08:41 #1
- Join Date
- Feb 2004
- Location
- Netherlands
- Posts
- 381
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Select from 2 tables, even when there nothing in table 2
Hi,
got two tables, IDs are matching.
table1
======
ID
table2
=======
ID
name
SELECT FROM `table1`,`table2` WHEN
table1.ID = table2.ID
But, it should also select the ids from table1 when there are no records in table 2 with the same ID, how to do that?
thanks in advance
-
Dec 30, 2008, 09:16 #2
- Join Date
- Nov 1999
- Location
- Mechanicsburg, PA
- Posts
- 7,294
- Mentioned
- 123 Post(s)
- Tagged
- 1 Thread(s)
Use the LEFT JOIN syntax. If there's nothing corresponding in table2, the fields will be null.
SELECT table1.ID
, table1.Field1
, table1.Field2
, table2.Field3
, table2.Field4
FROM table1 LEFT JOIN table2 ON table1.id = table2.idDave Maxwell - Manage Your Site Team Leader
My favorite YouTube Video! | Star Wars, Dr Suess Style
Learn how to be ready for The Forums' Move to Discourse
-
Dec 30, 2008, 09:38 #3
- Join Date
- Feb 2004
- Location
- Netherlands
- Posts
- 381
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
thanks, that did the trick, for some reason I still cannot grasp the join thingie in mysql.
Bookmarks