I'm trying to write a query that returns the same result from three different events, but I think I am doing it wrong. I can run my query against one event ID and it works. How can I select all three? Here's what I have so far:
SELECT * FROM `Registrations`
WHERE `Role` = "Attendee" AND `RegistrationStatus_ID` = "1" AND `DigSignature` IS NULL
AND `Event_ID` = "147" OR `Event_ID` = "155" OR `Event_ID` = "160"
SELECT *
FROM `Registrations`
WHERE `Role` = "Attendee"
AND `RegistrationStatus_ID` = "1"
AND `DigSignature` IS NULL
AND `Event_ID` in ("147", "155", "160")
SELECT * FROM `Registrations`
WHERE `Role` = "Attendee" AND `RegistrationStatus_ID` = "1" AND `DigSignature` IS NULL
AND (`Event_ID` = "147" OR `Event_ID` = "155" OR `Event_ID` = "160")
When you're mixing AND and OR, it's helpful to use parens to group things together. Even when it's not necessary for logic, it's sometimes helpful for others to understand your intentions.
AND
and OR
have equal precedence.
SELECT * FROM `Registrations`
WHERE `Role` = "Attendee" AND `RegistrationStatus_ID` = "1" AND `DigSignature` IS NULL
AND (`Event_ID` = "147" OR `Event_ID` = "155" OR `Event_ID` = "160")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With