I have the following SQL statement
SELECT be.*, it.order_number
FROM songs AS be
INNER JOIN
(
SELECT song_id, order_number
FROM items
WHERE order_status = 1
) it
ON be.id = it.song_id
INNER JOIN orders AS or
ON it.order_number = or.order_number
WHERE be.active = 0
I can’t seem to understand why this statement does not produce any results. When I remove the following line;
INNER JOIN orders AS or
ON it.order_number = or.order_number
It seems to produce results, and I know that the order_number does exist in the orders table – so it’s clearly incorrect syntax but i’m not sure where to go from here? Appreciate the help.
The problem in this particular instance is that the
orin the query is a reserved word. You can use that if you wish, but you’ll have to quote it, like soGenerally though, for readability, I’d avoid such names. If you have to quote it or escape it, it’s probably a bad name.