I have two tables:
News:
newsid, datetime, newstext
Picture:
pictureid, datetime, imgPath
Ideally I want a query to return the following kind of table:
Expand|Select|Wrap|Line Numbers
- newsid, newstext, numImages, date (date only- no time)
- 1 someText 4 2010-01-01
- null null 5 2010-02-01
SQL so far:
Expand|Select|Wrap|Line Numbers
- SELECT * FROM news as n LEFT OUTER JOIN (SELECT count(pictureid), datetime
- FROM picture GROUP BY DATE(datetime)) as p ON DATE(n.datetime) = DATE(p.datetime)
- UNION
- SELECT * FROM news as n RIGHT OUTER JOIN (SELECT count(pictureid),
- datetime FROM picture GROUP BY DATE(datetime)) as p ON
- DATE(n.datetime) = DATE(p.datetime)
The results;
Expand|Select|Wrap|Line Numbers
- newsid text datetime count() datetime
- 1 sometext 2011-01-16 1 2011-01-16
- 2 moo2 2011-01-19 NULL NULL
- 3 mooo3 2011-01-19 NULL NULL
- NULL NULL NULL 4 2011-01-14