Link to home
Start Free TrialLog in
Avatar of Nura111
Nura111

asked on

Using OR and AND in mysql query

HI how Can I change the syntax and still get the same meaning for the following sql query
I want one or more felds will be equal to 1 (a = 1 OR b = 1 OR c = 1) and that keywords = 1 always

whats wrong with I did?
SELECT
    count(*)
SELECT
    id
FROM
    ServiceRequests 
WHERE (a = 1 OR b = 1 OR c = 1) AND keywords = 1

Open in new window

Avatar of Norie
Norie

I don't see anything wrong with your criteria, but why do you have SELECT count(*) and SELECT(id)?

What are you trying to count, id?
ASKER CERTIFIED SOLUTION
Avatar of Kim Walker
Kim Walker
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Nura111

ASKER

Thanks!  another quick one please  Update field a to 0 in all records from 12-29-2011 until now
One way to change this syntax, but retain the same meaning, pending you clarify what the SELECT COUNT(*) SELECT id was intended to do. Let's say you start with this, though:

SELECT
    id
FROM
    ServiceRequests 
WHERE (a = 1 OR b = 1 OR c = 1) AND keywords = 1
;

Open in new window


Another way to write this is:

SELECT
    id
FROM
    ServiceRequests 
WHERE 1 IN (a, b, c) AND keywords = 1
;

Open in new window