For a while I always had my queries as one line:
SELECT * FROM table WHERE col = value ORDER BY id DESC
Now that I’ve been told multiple times not to use *, I’ve been trying to find a way to make longer queries readable. So far I have something like this:
SELECT table.id,
table.type,
table.name
FROM table
WHERE table.id > $lastId
AND table.type = $type
ORDER BY table.id ASC
This seems okay, but are there any best practices around that I should have a look at?
My MySQL stuff is done within the context of PHP.
i have it this way: