Created
April 3, 2012 13:50
-
-
Save meiwin/2292157 to your computer and use it in GitHub Desktop.
mig33 SQL (1)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Write a sql query that will return a list of duplicate phone numbers and the duplication count | |
select PhoneNumber, count(*) count | |
from TheTable | |
group by PhoneNumber | |
having count(*) > 1 | |
; | |
-- Write a sql query that will return a list of IDs with duplicate phone numbers | |
select ID | |
from TheTable | |
where PhoneNumber in (select PhoneNumber from TheTable group by PhoneNumber having count(*) > 1) | |
; | |
-- Write a sql query that will return a list of IDs with no duplicate phone numbers using an outer join with the result from 1. | |
select ID | |
from TheTable t1 | |
left outer join (select PhoneNumber, count(*) count | |
from TheTable | |
group by PhoneNumber | |
having count(*) > 1) | |
on t1.PhoneNumber = t2.PhoneNumber | |
where t2.PhoneNumber is null | |
; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment