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

How to find data between two columns with Sql?

I’m just learning Sql. I have a data with column names, for example: nkk, name, tps. How to find same ‘nkk’ data but different ‘tps’

enter image description here

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

>Solution :

Use a self-join whose joining condition is exactly what you described: nkk is equal, but tps is not equal.

SELECT t1.nkk, t1.name AS name1, t1.tps AS tps1, t2.name AS name2, t2.tps AS tps2
FROM your_table AS t1
JOIN your_table AS t2 ON t1.nkk = t2.nkk AND t1.tps < t2.tps

I use < rather than != so we only get one of each pair. Otherwise you’ll get both Aa Ac and Ac Aa.

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