Skip to content
Advertisement

How to get only first row grouped by multiple columns?

I want to select a few columns, but only keep the first row grouped by the columns.

If I use

It can give me two rows for one item_no, if item_type and item_name don’t match in the two rows.

sample output:

How do I make sure I only get the first row grouped by three columns?

Expected output:

I’m using BigQuery so standard SQL

Advertisement

Answer

You can do a group by item_no then get the mininum value of item_name and item_type.

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