0 Credit Cards - Mortgages - Mobile Phone - Debt Consolidation - Life Insurance

PDA

View Full Version : SQL Query Corker!!


Weirfire
Oct 12th 2005, 10:29 am
I've got a corker of a query that I'm trying to do. Not really sure whats the best way to go about this one but here's the description.


I want to select the number of elements from table A where;

the category field in table B = catx and has an id = idx which exists in table A as catid


Table A
id
catid

Table B
id
category

frankm
Oct 12th 2005, 10:33 am
I want to select the number of elements from table A where;
the category field in table B = catx and has an id = idx which exists in table A as catid
category

English to SQL:


SELECT COUNT(*)
FROM tablea a, tableb b
WHERE b.category = 'catx'
AND b.id = 'idx'
AND a.catid = b.id

should do the trick.

frankm
Oct 12th 2005, 7:12 pm
just curious: did it do what you wanted it to do ?

Weirfire
Oct 13th 2005, 4:11 am
It did indeed :) Thanks very much frank :D