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

where clause with composite primary key

For example I have a composite primary key on columns id, age in the following table:

id age name
1 23 John
2 24 Alex
3 22 Rob
4 20 Ella

can I somehow query the table using composite primary key in where clause, somehow like that:

SELECT * FROM table
WHERE primary_key < (3, 22)

with result like that:

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

id age name
1 23 John
2 24 Alex

I cannot query it like where id < 4 and age < 22 because it would compare every column separately.

>Solution :

You can compare tuples with other operators than just = or IN

So

where (id, age)  < (3, 22)

is valid SQL.

But I have to admit that I find that condition highly confusing given the column names chosen

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