Consider this query:
SELECT table1.id,
table1.review,
table1.time,
table2.author,
table2.title
FROM
table1, table2
WHERE table1.id = table2.id
AND table1.reviewer = '{$username}'
ORDER BY table1.id
I’m using the above quite a lot around my site’s code. I find that adding the table prefixes etc. before the column names can make the query very long and take up quite a lot of lines.
Is there a way to make the above query simpler/easier?
First of all, you may want to give shorter aliases to your tables. In addition, you are using the implicit join syntax which complicates the
WHEREclause, and is not recommended in general. You may want to use the more modern explicit syntax instead:Note that
JOINis a synonym forINNER JOIN, and theASkeyword is optional when defining table aliases. You can simply use... FROM table1 t1 ...instead of... FROM table1 AS t1 ....