mardi 10 mars 2015

SQLite obtain a MAX from 2 joins

Actually, I can obtain a MAX from table2 and table1 with:



SELECT table1.id, MAX(table2.date),
FROM table1
LEFT JOIN table2 ON table1.id = table2.table1_id


This works as expected.


The problem is now I need another MAX from table3:



SELECT table1.id, MAX(table2.date), MAX(table3.date),
FROM table1
LEFT JOIN table2 ON table1.id = table2.table1_id
LEFT JOIN table3 ON table1.id = table3.table1_id


But, results are not the one expected (random results in my array!). It seems like SQLite can't get the MAX from the 2 join tables.


Is-it necessary to make some subqueries ? I would avoid this if possible.


Aucun commentaire:

Enregistrer un commentaire