Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to rewrite query without parenthesis for MySQL 4.1.22? 1

Status
Not open for further replies.

Spork52

Programmer
Nov 20, 2007
134
US
How can I rewrite a nested query without parenthesis so that it works in MySQL version 4.1.22? (parenthesis work fine in version 5.0.41)

I've got something like this:

SELECT fields
FROM tableA
JOIN tableB
ON tableA.tableA_id = tableB.tableA_id
LEFT JOIN
(tableX JOIN tableY
ON tableX.tableX_id = tableY.tableX_id
AND tableY.date = '2007-11-19')
ON tableB.tableB_id = tableX.tableB_id

(The expression in parenthesis is often NULL either because there are no entries in tableY with the particular date, or because there are no entries in tableX that join with tableY for the particular date)
 
Code:
SELECT fields 
  FROM tableA 
INNER
  JOIN tableB 
    ON tableB.tableA_id = tableA.tableA_id
LEFT OUTER
  JOIN (
       SELECT tableX.tableB_id
         FROM tableX 
       INNER
        JOIN tableY 
          ON tableY.tableX_id = tableX.tableX_id
         AND tableY.date = '2007-11-19'
       ) [b]AS dt[/b]
    ON [b]dt[/b].tableB_id = tableB.tableB_id

r937.com | rudy.ca
 
Thank you so much. That worked. All I had to do was modify the field lists a bit.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top