SQL Server : left join results in fewer rows than in left table -
i using sql server (i believe 2005).
i have tablea has 2 columns , 439 rows (each row unique).
+----------+ |id | name | +----------+ i have tableb has 35 columns , many hundreds of thousand rows (each row unique).
+------------------------------------------------------------------------------+ |date | id | name | blah1 | blah2 | ... | hour1 | hour2 | hour3 | ... | hour24 | +------------------------------------------------------------------------------+ each row in tableb has hourly observations , other house keeping information. testing purposes interested in today's date i.e 4/19/2013.
if do:
select count(*) tableb date = '4/19/2013 12:00:00 am' i 10526, correct there 10526 distinct locations there hourly observation data each day.
i want left join tablea , tableb on a.id = b.id, should produce result has 439 rows.
unfortunately, result has 246 rows. how can be? isn't left join suppose return rows in tablea regardless of whether there match in tableb?
*edit*
the complete query used was:
select * tablea left join tableb b on a.id = b.id realdate = '4/20/2013 12:00:00 am'
try this:
select * tablea left join (select * tableb realdate = '4/20/2013 12:00:00 am') b on a.id = b.id or this:
select * tablea left join tableb b on (a.id = b.id , realdate = '4/20/2013 12:00:00 am')
Comments
Post a Comment