Alain Bertrand wrote:
Puneet Kishor a écrit :
without seeing the data, a good guess would be, "Yes."
What do you mean ? That my query is syntaxically wrong ?
Your query is syntactically correct in that it returns a result without
the SQL engine generating a syntax error... it just doesn't seem to be
producing what you want, hence it is perhaps logically incorrect, non!.
LEFT JOIN selects all the rows with values from the left table and
either matching values or NULL from the right table.
Yes, I know, not very well because I have only a basic knowledge of sql
(this query has been written by a friend), but this is what I want.
This may look complicated for just counting the number of rows, but in
fact this a kind of minimum example to reproduce the problem I have with
a more complex query.
If you just had JOIN then you would get only those rows where both left
and right sides match (the result set would have fewer records than...)
if you have LEFT (or RIGHT) JOIN whereby you will get all the rows where
the left side matches, and NULL for where right side doesn't match (the
result set would have more records).
Try SQLzoo.net for very nice tutorials with basic to intermediate SQL.