Skip to content
Advertisement

how to select distinct values from a table when i need to select values having y if it has both y,n values and n values only if there is no y value

i have a table with data like

i want distinct promo ,flag from the table but when a single promo has both Y,N flags i want only Y FLAG PROMO

i.e expected output

need help in building a simple query

like

Advertisement

Answer

You can use analytical function like this:

You can also use group by but it will restrict you to select any other columns from table in the result.

Also, in group by query, it will be case insensitive so , I would recommend to use analytical function.

Cheers!!

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement