oracle - SQL select all distinct rows from first column with random values from other columns -


i have this:

id      email       email2      id_2 ------------------------------------------ 1       james@      james2@        11           1       james@      james2@        11           1       james@         -           11   1       james@         -           11   2       declan@     dylan2@        22           2       declan@     dylan2@        44         3       john@          -           33 3       john@          -           33          4       vito@       vito2@         55 

so need select values distinct id, if email2 not empty should choose 1 not empty email2, if there empty email2, choose one. example:

id      email       email2      id_2 ------------------------------------------ 1       james@      james2@        11                2       declan@     dylan2@        22           3       john@          -           33          4       vito@       vito2@         55 

there isn't more conditions don't know do. use partiotion or group by.. please , me.

given sample data, using max or min aggregate should desired results:

select id, max(email), max(email2), min(id_2) yourtable  group id 

Comments

Popular posts from this blog

unity3d - Rotate an object to face an opposite direction -

angular - Is it possible to get native element for formControl? -

javascript - Why jQuery Select box change event is now working? -