I have a simple (I suppose) problem, which is baffling me (I'm not a SQL expert as you will see soon... :-).
I have a table person
with fields id
and name
, and a table comment
with field id
, id_person
and text
:
---------------
table: person
---------------
id | name
---------------
---------------------------
table: comment
---------------------------
id | id_person | text
---------------------------
The comments are linked to persons on person.id
=> comment.id_person
.
Each person can have many comments.
I would prefer no to save the number of comments in any table.
The question is: How to select all persons with at least N comments?
This is what I am trying right now, but it's of course wrong...:
SELECT * FROM person WHERE (SELECT COUNT(*) FROM comment WHERE id_person = 2) >= N
P.S.: I'm currently working with sqlite, but a standard SQL answer is fine...