I have a little problem with my MySQL query. I'm using LEFT JOIN to table1 and table2. But many rows in table2 can match one row in table1. I know that LEFT JOIN stop searching when it finds one match row, but it seems to do this randomly. Even when I sort table2 it doesn't take first match row.
Do you know maybe a solution?
Example:
table1
date1 |
-----------
2010-10-10 |
2010-10-10 |
2010-10-10 |
table2
date2 | item
-------------------------
2010-10-09 | item1
2010-10-08 | item2
2010-10-07 | item3
SQL query
SELECT * FROM table1 LEFT JOIN table2 ON date2<=date1
I expect
date1 | date2 | item
--------------------------------------
2010-10-10 | 2010-10-09 | item1
2010-10-10 | 2010-10-09 | item1
2010-10-10 | 2010-10-09 | item1
but I'm getting f.e
date1 | date2 | item
--------------------------------------
2010-10-10 | 2010-10-09 | item1
2010-10-10 | 2010-10-08 | item2
2010-10-10 | 2010-10-09 | item1
GROUP BY? That might explain an undeterministic result in MySQL What is your exact query? - Martin Smith