Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Check if columns in SQL table have the same values

I have a BigQuery table like below

enter image description here

I want to return the rows whose col_1, col_2, and col_3 values are not the same.
In the example above, it should return the 2nd and 3rd row (with key ghj-ikl and tgl-pkl). All 3 columns have to have the same values.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

How can I do that?
Thanks

>Solution :

Consider below approach (BigQuery Standard SQL)

select * from your_table 
where (
  select count(distinct el) > 1
  from unnest([col_1, col_2, col_3]) el
)    

if applied to sample data in your question – output is

enter image description here

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading