sql >> Database >  >> RDS >> Mysql

LEFT OUTER JOIN met voorwaarden (waar, bestellen op)?

Probeer deze Query, het geeft je elke training en de meest recente trainingsgeschiedenis voor elke:

SELECT tc.id, tc.name, tc.order, 
th.id as history_id, th.finished_at, th.score
FROM trainings tc
LEFT OUTER JOIN training_histories th ON th.training_id = tc.id 
    and th.id =
    (SELECT th1.id from training_histories th1 where th1.training_id = tc.id
     and th1.finished_at is not null
     order by th1.finished_at desc limit 1)
WHERE tc.id > 4
AND tc.id < 8
GROUP BY tc.id
ORDER BY tc.order_by ASC, tc.id ASC


  1. Hoe importeer ik een Excel-bestand in SQL Server?

  2. PostgreSQL:hoe de plpythonu-extensie te installeren

  3. MySQL mislukt op:mysql ERROR 1524 (HY000):Plugin 'auth_socket' is niet geladen

  4. MySQL-fout 150, kan geen tabel maken