Jump to content

[SOLVED] MySQL seemingly failing simple AND/OR query


webent

Recommended Posts

MySQL Version - 4.1.22-standard-log

 

Hi, for the life of me I can't figure out why my query is failing, is it me or is it a bug? Correct me if I'm mistaken, but doesn't an "AND" statement require that it must meet the criteria on both sides of the statement? Here's my code with some values already in place...

 

SELECT DISTINCT product_line FROM db.products WHERE product_vendor = 'TestingVendor' AND product_line = 'Automotive' OR product_line = 'Collectibles' OR product_line = 'VIDEO CONFERENCING' OR product_line = 'VIDEO EDITING - HARDWARE'

 

Now, Automotive and Collectibles are not product_lines that belong to product_vendor = 'Testing_Vendor', so therefore shouldn't show up, but they are showing up, can someone please tell me what's going on with that?

Link to comment
Share on other sites

When mixing AND and OR, use (..)s to indicate the correct logic

 

Is it

(A AND B) OR C

or

A AND (B OR C)

 

Another thing you can do in your case is use "IN"

 

SELECT DISTINCT product_line 
FROM db.products 
WHERE product_vendor = 'TestingVendor' 
AND product_line  IN ( 'Automotive' , 'Collectibles' , 'VIDEO CONFERENCING'  'VIDEO EDITING - HARDWARE')

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.