MySQL Forums
Forum List  »  Newbie

Re: simple mysql query...
Posted by: Felix Geerinckx
Date: October 31, 2005 09:03AM

Gawie Marais wrote:

> SELECT count(sid) FROM system WHERE customercode = '$customercode' AND pkgid = '9' or pkgid = '10' or pkgid = '11' or pkgid = '12'
>
> its returning the count for all records where customercode = $customercode in stead of also
> taking into account that pkgid must also be = to 9,10,11,12

You have your precedence wrong.
You could write (note the parentheses):

SELECT count(sid) FROM system WHERE customercode = '$customercode' AND (pkgid = 9 or pkgid = 10 or pkgid = 11 or pkgid = 12)

But the standard way is:

SELECT count(sid) FROM system WHERE customercode = '$customercode' AND pkgid IN (9, 10, 11, 12)

Also note that, at least when pkgid has a numeric datatype (e.g. INTEGER), you don't want to write quotes around the literal values 9, 10, 11 and 12; the same holds for customercode.

--
felix
Please use BBCode to format your messages in this forum.

Options: ReplyQuote


Subject
Written By
Posted
October 31, 2005 08:28AM
Re: simple mysql query...
October 31, 2005 09:03AM
October 31, 2005 01:04PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.