I am having trouble with a SQL query. I would like to join the following 2 queries that work indiviually into one query.
This query should return 0 which is what I expect
SELECT COUNT(*) FROM table3 INNER JOIN table1 ON
table3.id = table1.id
WHERE table3.somefield = '0' AND table1.field1 = '1' AND table1.field2 = 'something') AS counts
This query should return 2 which is what i expect
SELECT COUNT(*) FROM table3 INNER JOIN table2 ON
table3.id = table2.id
WHERE table3.somefield = '0' AND table2.field1 = '1' AND table2.field2 = 'something') AS counts
I've combined the queries and moved the conditions to the JOIN but that causes the query to count too many rows
SELECT COUNT(*) FROM table3
LEFT JOIN table1 ON
table3.id = table1.id AND (table1.field1 = '1' AND table1.field2 = 'something')
LEFT JOIN table2 ON
table3.id = table2.id AND (table2.field1 = '1' AND table2.field2 = 'something')
WHERE table3.somefield = '0'
What i expect is for the first part of the query, it should return 0, the second part should be 2 but what gets output is 148 and it's got to be to do with the AND condition in the JOIN.
What is going wrong here?