sql - Select unique records -


i'm working table has 50 colums , 100,000 rows.

one column, call typeid, has 10 possible values:

1 thourgh 10.

there can 10,000 records of typeid = 1, , 10,000 records of typeid = 2 , one.

i want run select statement return 1 record of each distinct typeid.

so like

typeid    jobid    language    billingdt    etc ------------------------------------------------ 1         123      en          20130103     etc 2         541      fr          20120228     etc 3         133      fr          20110916     etc 4         532      sp          20130822     etc 5         980      en          20120714     etc 6         189      en          20131009     etc 7         980      sp          20131227     etc 8         855      en          20111228     etc 9         035      jp          20130615     etc 10        103      en          20100218     etc 

i've tried:

select distinct typeid, jobid, language, billingdt, etc 

but produces multiple typeid rows of same value. whole bunch of '4', '10', , on.

this oracle database i'm working with.

any advise appreciated; thanks!

you can use row_number() top n per group:

select  typeid,          jobid,          language,          billingdt,          etc    (   select  typeid,                      jobid,                      language,                      billingdt,                      etc,                     row_number() over(partition typeid order jobid) rownumber                t         ) t   rownumber = 1; 

sql fidle

you may need change order by clause fit requirements, you've not said how pick 1 row per typeid had guess.


Comments

Popular posts from this blog

java.util.scanner - How to read and add only numbers to array from a text file -

rewrite - Trouble with Wordpress multiple custom querystrings -