I have trouble with a query, the problem is that i am left joining three times from the same table.
The query in question is this:
SELECT
o.order_id,
n.title,
c.first_name,
tdv5.tid,
tdv6.name,
tdv8.name AS settlement_month
FROM orders o
join products p on o.product_id = p.nid
join node n on p.nid = n.nid
join customers c on o.customer_email = c.customer_email
join term_node tn on tn.nid = p.nid
join term_data tdv6 on tn.tid = tdv6.tid AND tdv6.vid = 6
left join term_data tdv5 on tn.tid = tdv5.tid AND tdv5.vid = 5
left join term_data tdv8 on tn.tid = tdv8.tid AND tdv8.vid = 8
When i am using this query only the first JOIN using tn.tid will work. For an example if the only join of the last three is this:
join term_data tdv6 on tn.tid = tdv6.tid AND tdv6.vid = 6
It will work fine. The same with
left join term_data tdv5 on tn.tid = tdv5.tid AND tdv5.vid = 5
And
left join term_data tdv8 on tn.tid = tdv8.tid AND tdv8.vid = 8
However when i combine them, they won’t work at all. Only tdv6 works when i combine the three queries.
Do you have suggestions on what is wrong? Thanks.
If you try putting a WHERE clause, like this: