I have an MySQL Query looks like that:
SELECT
client.id, client.vorname, client.nachname, DATE_FORMAT(geburtsDatum, '%d.%m.%Y'), zahlung.zuUebBet, zahlung.betrag
FROM
zahlung JOIN client ON ( zahlung.mitgliedsNr = client.id )
WHERE
client.typ = 'U'
OR
client.typ is null
AND
zahlung.typ = 'Beitrag'
AND
anBGueberwiesen = '0000-00-00'
AND
zahlung.zuUebBet IS NOT NULL
AND
(
zahlung.vomBGeinheb = 0
OR
zahlung.vomBGeinheb is null
)
All work fine but the case:
zahlung.zuUebBet IS NOT NULL
looks like beeing ignored. (I get rows with lots of NULL in it)
Anyone know whats going on?
please take a look at the operator precedence of mysql.
ORhas a lower precedence thanAND, so you’ll have to put this into braces to get the desired result:the complete WHERE-block should look like this:
otherwise, the sql-statement would be treated like the following (wich isn’t what you wanted, i think) (i’ve added braces to make things clear):