This is likely very easy, I haven’t used sql in a while and have run into this problem. Basically, as part of a larger statement I only want to return a row from a select statement if a count from an inner select statement is equal to 3. How do I do that?
For example…
select rev.name, s.title
from reviewer rev, song s, rating r
where (r.rID = rev.rID) and (r.mID = s.sID) and ...[rest goes here];
Where the ‘rest’ is that I only want to return when reviewer rev has reviewed song s twice, and r.value was larger the first time (we denote first time as the one with the oldest r.date_of_rating.
This is clearly a count and compare, but I don’t know how to lay it out in proper SQL syntax. Any help would be greatly appreciated. Thanks
I’m not sure your example gives enough info.
But it sounds like you need a ‘HAVING’ clause.
e.g.