-2
Hello. I need to make a query in Mysql where there are JOINS of 4 tables, all tables have the column data_cadaster, I need the selection to return only the record where the data_cadaster is the largest of all these tables. How can I do that?
My current Query is:
SELECT *
FROM
(`cursos_aulas`) LEFT JOIN `cursos_aulas_arquivos` ON cursos_aulas_arquivos.cursos_aulas_id_fk = cursos_aulas.cursos_aulas_id
LEFT JOIN `cursos_aulas_videos` ON cursos_aulas_videos.cursos_aulas_id_fk = cursos_aulas.cursos_aulas_id
LEFT JOIN `cursos_aulas_imagens` ON cursos_aulas_imagens.cursos_aulas_id_fk = cursos_aulas.cursos_aulas_id LEFT JOIN `cursos_aulas_exercicios` ON cursos_aulas_exercicios.cursos_aulas_id_fk = cursos_aulas.cursos_aulas_id
WHERE
cursos_aulas.cedoc_doc_id_fk = '16360'
ORDER BY
`cursos_aulas_imagens_id` desc,
`cursos_aulas_arquivos_id` desc,
`cursos_aulas_videos_id` desc
I forgot to inform an important detail, the field data_registration exists in all, except in the table courses. The intention is to take the class that was last registered and the classes are divided into different tables, one for video lessons, another for archive sessions (pdf, doc and the like) and so on. Ai want to recover the last class registered, comparing the values of the data_register of each of them and returning only the values of the record of the table that contains the class registered.
– Raphael Cordeiro
Got it. I edited my answer. Unfortunately I don’t have Mysql installed now to test. See if the command works
– Daniel Giacomelli