I have some code that's been in production for a few years and now is presenting a problem. The following is on a mysql 3.23.38 server:

SELECT b.denewbs, b.dewrbtr, b.dekostl, b.desgtxt, b.deprojk,
       b.degeber, b.de_heid, c.acdesdc, c.acfund
FROM headers a, details b, acctref c
WHERE a.he_baid = ? AND
      b.de_heid = a.heid AND
      (c.acfund = b.dekostl OR
       c.acfund = b.deprojk OR
       c.acfund = b.degeber)
ORDER by acfund;

Note: The ? is a placeholder for DBI.

My problem is this - there is a value that is placed in one, and only one, of dekostl, deprojk, or degeber for each record and this value corresponds to a value in acfund, thus the OR statements. However, some values have recently been removed from acfund, affecting reports where these deleted values are still in existence in the other fields, so I need to add a left join, I suppose. Now in Oracle, I could simply use (+) in all three places. In mysql, I know how to do this with one simple comparison, but not with three.

I've tried the following and it didn't like the OR statements. It worked with AND, but of course, there was no acdesc or acfund in the output because it didn't match all three conditions - the acfund is only in one of dekostl, deprojk or degeber - and which one is not known for each record, so I need to check all three.

SELECT denewbs, dewrbtr, dekostl, desgtxt, deprojk,
       degeber, de_heid, acdesc, acfund
FROM (details INNER JOIN headers ON details.de_heid = headers.heid)
LEFT JOIN acctref ON ((details.dekostl = acctref.acfund) OR
                      (details.deprojk = acctref.acfund) OR
                      (details.degeber = acctref.acfund))
WHERE (((headers.he_baid)=38));

at a loss,
-Mike


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to