jeudi 4 février 2016

SQL query on nested select (maybe?)

My simplified schema is as follows:

Table1(id, age, name)
Table2(id1, id2)

I need to compare the age between the IDs in Table2 and return the name of ID1 if ID1 is older than ID2.

I am able to get the age of ID1 and compared it to an arbitrary age, say 20:

SELECT name from (Table1 INNER JOIN Table2 
                 on Table1.id1 = Table2.id1 
                 where age > 20);

But how should I get the age of ID2 to replace the "20" there? Thanks in advance

Aucun commentaire:

Enregistrer un commentaire