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

Nura111Asked:
Who is Participating?
 
Kim WalkerWeb Programmer/TechnicianCommented:
Try this:
SELECT
    count(*)
FROM (
    SELECT
        id
    FROM
        ServiceRequests 
    WHERE (a = 1 OR b = 1 OR c = 1) AND (keywords = 1);
)

Open in new window

0
 
NorieVBA ExpertCommented:
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?
0
 
Nura111Author Commented:
Thanks!  another quick one please  Update field a to 0 in all records from 12-29-2011 until now
0
 
Kevin CrossChief Technology OfficerCommented:
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

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.