Reputation: 1
I have a table with two columns:
id | num |
---|---|
1 | 2 |
2 | 8 |
1 | 7 |
7 | 3 |
I want to get as an answer to my query only ids that have more than 1 nums. For example in my table I would want to get as a result:
id |
---|
1 |
How should I express my query? Thanks in advance.
Upvotes: 0
Views: 49
Reputation: 98
You might need something like this:
SELECT id
FROM your_table_name
GROUP BY id
HAVING count(DISTINCT num) > 1;
Google 'Aggregate functions'. Here the aggregate function is count() and it works always coupled with a GROUP BY clause. Pretty fun.
Upvotes: 4