May 10, 2007 at 8:54 pm
How can I combine this into one query?
select count(*) from table1 a
left join table2 b on a.id = b.id
where a.field1 = 1
and a.field2 = 2
select count(*) from table2 b
left join table1 a on a.id = b.id
where a.field1 = 1
and a.field2 = 2
May 10, 2007 at 10:43 pm
Condition
where a.field1 = 1
and a.field2 = 2
makes all rows from table1 mandatory, so LEFT JOIN from second query does not work.
Not sure what do you really mean but probably it must be like this:
select count(*)
from table2 b
FULL OUTER join table1 a on a.id = b.id AND a.field1 = 1 and a.field2 = 2
_____________
Code for TallyGenerator
Viewing 2 posts - 1 through 1 (of 1 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy