Last active
May 16, 2016 16:57
-
-
Save andrewcrabb/d19998a8e72647a00825172adac5bd4a to your computer and use it in GitHub Desktop.
Postgresql examples
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
# Grouping, case insensitive | |
SELECT lower("subjects"."name_last"), lower("subjects"."name_first"), lower("subjects"."history") FROM "subjects" GROUP BY lower(subjects.name_last), lower(name_first), lower(history) HAVING count(*) > 1; | |
# Another way | |
select name_last, name_first, history | |
from subjects | |
where (upper(name_last), upper(name_first), upper(history)) in | |
(select upper(name_last), upper(name_first), upper(history) | |
from subjects | |
group by upper(name_last), upper(name_first), upper(history) | |
having count(*) > 1) | |
order by name_last; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment