I have the following SQL statement. Which is working okay. Except in some cases the processing of the query takes a lot of time, resulting in a system time out. So I need to convert the statement. Probably with a JOIN.
I can't figure out how to convert this statement:
SELECT table1.id as id,
table1.firstname,
table1.lastname,
table3.name,
table4.name
FROM table1, table2, table3, table4, table5
WHERE table1.id = table2.tabel1id
AND table2.table2id = table3.table2id
AND table3.table3id = table5.table3id
AND table5.somecode = '5'
AND table3.table3id = table4.name
AND table1.firstname LIKE '%John%'
GROUP BY table1.id
ORDER BY table3.name, table1.firstname, table1.lastname
I have the nesting of the tables and I also want to use the results of subqueries in the final SELECT (table3.name and table4.name)