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:

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

Leave a Reply