I have a query like this one :
SELECT DISTINCT
`a`.*,
`b`.*,
`c`.*
FROM `a`
INNER JOIN `b` ON (`b`.`a_id` = `a`.`id` )
INNER JOIN `c` ON (`c`.`id` = `b`.`c_id`)
WHERE (
(`a`.`id` = 12345) AND
(`b`.`foo`= "bar")
)
Basically, this takes the row from a with id=12345, and the rows from b that concern this row, as well as the rows from c about this b rows, only of the rows in b have foo=bar
Right now, if there is no b row that has foo=bar, the a row is not even returned. This is wrong. I want that no matter what the matching a row is returned (whether there are bs and cs). How can I do this? (is there a way?)
I think you should look up how to do OUTER JOINS. It sounds like that might be what you are asking for.
Something like:
EDIT: with new information (a condition on b, which has to have a column foo=bar. This works when there is no row in b at all. but if there is one with foo=notbar, I want it to return a as well), try this. Note: I removed tics to make it easier to read and see quotes.