Subject: Categories and Items query
| From: | Neil Smth | Date: | Wed, 31 Dec 2003 14:36:39 +0000 |
| Subject: | Subject: Categories and Items query | ||
| References: | 1 | Groups: | php.db |
| Request: | Send a blank email to php-db+get-32231@lists.php.net to get a copy of this message | ||
At 01:11 31/12/2003 +0000, you wrote:
To: php-db@lists.php.net Message-ID: <3FF1B61E.5070909@comcast.net> Date: Tue, 30 Dec 2003 12:30:06 -0500 From: Ali Van Doren <alikat@comcast.net> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Subject: Categories and Items query<snip>
$query = "SELECT category, feature_description FROM features as f, feature_categories as fc WHERE f.feature_category_id=fc.feature_category_id AND f.featureset_id = '1' OR f.featureset_id = '3' ORDER BY f.feature_category_id ASC";<snip>
So, I actually have two questions: 1) Does anyone know why my query is misbehaving so badly?I think it's because you need to put the OR statements in brackets, which will then return results with .... AND (f.featureset_id = '1' OR f.featureset_id = '3' ) Where you are getting results more like ... AND f.featureset_id = '1' then *also asking* for additional results matching "f.featureset_id = '3' " Do you see the difference in the way the SQL interprets your query ? Its quite subtle. Anyway usually to avoid confusion in cases like this I would use the IN construct, its less verbose and you can construct an IN list by using PHP's join(",",featureset) function .... AND f.featureset_id IN ( '1','3' ) Hope that helps. Neil.