This is my table in which the information about the owner of the apartment, the number of the house in which the apartment is located, etc. The owners of the same apartment can be two different people, for this is responsible column Fraction, which shows a certain part of the apartment owned by a person.
My task is to display all the information if one apartment is owned by two people?
Accordingly, as a result, I should get apartment number 9 in house number 14
I think you want:
SELECT House_Number, Apartment_Number
FROM yourTable
GROUP BY House_Number, Apartment_Number
HAVING MIN(Owner) <> MAX(Owner);
The above logic will detect anyone house and apartment having more than one unique owner.
This works for me:
select Owner
from HOMES
where (House_Number, Apartment_Number) in (select House_Number
,Apartment_Number
from HOMES
group by House_Number
,Apartment_Number
having count(*) > 1)
See this db<>fiddle and also refer to this SO question:
MySQL multiple columns in IN clause
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.