SQL Query; How to get only records with two matching fields -
i hope can explain properly, little confusing. need query records have same "origin" , same "destination". rows each have origin , destination. need see in both match. instance, if there row seattle (origin) , portland (destination) need see other records seattle origin , portland destination. additionally, need see records type of match. if there records same origin , same destination (not seattle , portland), displayed. make sense? can help?
if understand well, wanna find duplicates on fields.
you can do
select * yourtable t join (select origin, destination yourtable group origin, destination having count(*) > 1) m on t.origin = m.origin , t.destination = m.destination
if don't need fields, do
select origin, destination, count(*) yourtable group origin, destination having count(*) > 1
Comments
Post a Comment