I have some troubles re-writing this query to using joins instead of the two subqueries. I have a problem untangling it, if you know what i mean.
SELECT o.order_id, n.title, c.first_name, t1.name, o.product_id,
(SELECT ttd2.tid FROM term_data ttd2, term_node ttn2 WHERE ttd2.vid = 5 AND ttn2.nid = p.nid AND ttd2.tid=ttn2.tid) AS tid,
(SELECT ttd4.name FROM term_data ttd4, term_node ttn4 WHERE ttd4.vid = 8 AND ttn4.nid = p.nid AND ttd4.tid=ttn4.tid) AS month
FROM orders o, products p, node n, customers c, term_data t1, term_node t2
WHERE o.product_id = p.nid
AND p.nid = n.nid
AND o.customer_email = c.customer_email
AND t2.tid = t1.tid
AND t1.vid = 6
AND n.nid = t2.nid
Can you help? Or give some clues/hints.
Rewrite it using ANSI SQL-92 syntax (i.e., using JOIN and ON clauses), and it should be much more clear.
Right now all of your
JOINandWHEREclauses are mixed together, so it is not easy to see the relationships. Subqueries are not necessarily a problem; this should become more clear once the syntax is cleaned up.