[thelist] SQL subqueries in mySQL 3.23.54

Tab Alleman Tab.Alleman at MetroGuide.com
Mon Mar 1 15:52:56 CST 2004


Tab Alleman wrote:
> john at johnallsopp.co.uk wrote:
> 
>> SELECT * FROM A, B, C where A.id = B.id and A.id = C.id and (select
>> count(*) from A, B where A.id = B.id) > (select count(*) from A, C
>> where A.id = C.id)
> 
> Oooh, a puzzle!  Let's see,
> 
> SELECT * FROM A
> INNER JOIN B ON A.id=B.id
> INNER JOIN C ON A.id=C.id
> HAVING COUNT(B.id) > COUNT(C.id)
> 
> 
> Does that do it?

Oops, no they'd need to be OUTER joins or else you won't get any rows
when both B & C don't have rows.


More information about the thelist mailing list