How to find owners who own more than one apartment in the same house?

There is a table, how to find owners who own more than one apartment in the same house?
id|flat_num|house_id|owner_id|
1/12 |2 |1 |
2/22 |3 |3 |
3/10 |3 |3 |
4/30 |1 |2 |
5/12 |2 |4 |
6/22 |3 |4 |
April 7th 20 at 15:46
3 answers
April 7th 20 at 15:50
Solution
SELECT owner_id FROM tableName 
GROUP BY owner_id
HAVING count(house_id) > 1;
April 7th 20 at 15:52
April 7th 20 at 15:48
Solution
SELECT owner_id FROM t1
GROUP BY owner_id, house_id 
HAVING count(owner_id, house_id) > 1;
count sort takes one argument, at least in ms sql - Marjorie.Schmeler commented on April 7th 20 at 15:51
@Kaitlyn.Lebsack, there is no way now to test, but like count() in MySQL can take any group. - elijah.Kuhn commented on April 7th 20 at 15:54
@Carmela.Flatley, no, it will not work. - Obie.Strom commented on April 7th 20 at 15:57

Find more questions by tags SQL