sql - SELECT DISTINCT is not working -


let's have table name tablea below partial data:

lookup_value     lookups_code     lookups_id ------------     ------------     ----------           5%              120           1001           5%              121           1002           5%              123           1003           2%              130           2001           2%              131           2002 

i wanted select 1 row of 5% , 1 row of 2% view using distinct fail, query is:

select distinct lookup_value, lookups_code   tablea; 

the above query give me result shown below.

lookup_value     lookups_code      ------------     ------------                5%              120                      5%              121                      5%              123                      2%              130                      2%              131            

but not expected result, mt expected result shown below:

lookup_value     lookups_code      ------------     ------------                5%              120                                           2%              130            

may know how can achieve without specifying clause? thank you!

i think you're misunderstanding scope of distinct: give distinct rows, not distinct on first field.

if want 1 row each distinct lookup_value, either need where clause work out 1 of them show, or aggregation strategy group by clause plus logic in select tells query how aggregate other columns (e.g. avg, max, min)


Comments

Popular posts from this blog

multithreading - Exception in Application constructor -

React Native allow user to reorder elements in a scrollview list -

windows - CertCreateCertificateContext returns CRYPT_E_ASN1_BADTAG / 8009310b -