sql confusion LEFT JOIN = BETWEEN
Is it possible to check values using BETWEEN and '=' in left join?开发者_如何转开发 Something like this ...
LEFT JOIN abc
ON abc.date = BETWEEN $a AND $db
This query isnt working :( .any solution?
The syntax you are looking for is:
LEFT JOIN abc
ON abc.date BETWEEN $a AND $b
Ie. You need to remove that =
.
There is no equality sign before the between. I dont know much about PHP, but SQL usually expects dates in an appropriate format, usually YYYY-MM-DD, and some DBMS do accept other formats as well, such as MM/DD/YYYY, being able to recognize them.
And note that there is no actual joining between the a and abc tables, so, for every register in 'a', SQL will include all the columns in 'abc', but with no record. You have to actually join the tables, using something as such:
select *
from a
left join abc
on a.ID = abc.ID
and abc.date between '$a' and '$db'
You can stull filter by any criteria, but you must join the tables. The difference is, when there is no match between the left table (a) and the right table (abc), the right data will be shown as NULLs in the result.
Hope it helps and be useful.
精彩评论