Reputation: 5577
I have two tables :
ad ( id(int) , userid(int) )
: table to store advertisement which have a user column
adcat ( adid(int) , catid(int) )
: table to store the category id (catid) of each ad (adid)
now all I want is to get the number of ads of a specific category published by a specific user
example : all the ads of catid = 1 and with userid = 725
Thank you
Upvotes: 1
Views: 68
Reputation: 92785
SELECT COUNT(*) ads_total
FROM ad a JOIN
adcat c ON a.id = c.adid
WHERE c.catid = 1 AND
a.userid = 725
Upvotes: 2
Reputation: 11712
you need to join the tables:
SELECT * FROM ad INNER JOIN adcat ON adid=id WHERE catid=1 and userid=725;
Upvotes: 1
Reputation: 31
SELECT * FROM ad
LEFT JOIN adcat
ON adcat.adid = ad.id
WHERE adcat.catid = 1 AND ad.userid = 725
Upvotes: 3