tags:

views:

69

answers:

2

I have the following query

SELECT * 
FROM attend
RIGHT OUTER JOIN noattend ON attend.date = noattend.date2
WHERE attend.date
BETWEEN '2010-02-01'
AND '2010-04-01'
AND attend.customerid =1
ORDER BY date DESC 
LIMIT 0 , 30

Attend is the table with customerid noattend is the table with a row for each date (date2) I followed the advice in other questions to right outer join it to create values where there is no record in attend but it still isn't filling in the empties any help much appreciated

A: 

If you say that noattend is a table with a row for each date, you should use it in WHERE clause:

WHERE noattend.date2 BETWEEN (.....

And I think it's more clear to use LEFT JOIN :

SELECT * 
FROM noattend
LEFT OUTER JOIN attend ON (attend.date = noattend.date2 AND attend.customerid =1)
WHERE noattend.date2
BETWEEN '2010-02-01'
AND '2010-04-01'
ORDER BY date DESC 
LIMIT 0 , 30
a1ex07
thanks I tried what you suggested but it only seems to be pulling in a few extra null rows (i think null rows are fine as long there is the date there) I got 25 with mine and 30 with yours. Any ideas?
bsandrabr
now I feel dumb might help if I took out the limit clause
bsandrabr
A: 

You need to get rid of the SELECT * and list your column names instead. Where you want the date to be, use the field noattend.date2, not attend.date. Attend.date will be NULL (blank) for those extra rows created to fill in your "missing" dates.

Something like:

 SELECT attend.id, attend.name, noattend.date2
 FROM . . .  (continue your code here)
Larry Lustig
good point thanks also the last bit had to be order by date2 desc
bsandrabr