[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 217
  • Last Modified:

mysql query issue

Hi:
I have the query below however even so the product is inactive in the database (active = 0) it still shows with the query below even so I require products.active = 1. Any ideas about what I am doing wrong?
SELECT * FROM products 
LEFT JOIN usertable ON usertable.idusr = products.vendorID 
LEFT JOIN products_keywords ON products_keywords.IDproducts = products.id 
WHERE products.ProdName LIKE %s OR products.ProdShortDesc LIKE %s OR products.ProdLongDesc LIKE %s OR usertable.company LIKE %s OR products_keywords.keyword2 LIKE %s AND products.active = 1

Open in new window

0
michael789
Asked:
michael789
1 Solution
 
Guy Hengel [angelIII / a3]Billing EngineerCommented:
you are missing ()-;
SELECT * FROM products 
LEFT JOIN usertable ON usertable.idusr = products.vendorID 
LEFT JOIN products_keywords ON products_keywords.IDproducts = products.id 
WHERE ( products.ProdName LIKE %s OR products.ProdShortDesc LIKE %s OR products.ProdLongDesc LIKE %s OR usertable.company LIKE %s OR products_keywords.keyword2 LIKE %s)
  AND products.active = 1

Open in new window

0
 
DABOMBCommented:
angelIII is correct, your 'AND products.active' is only being connected with the 'products_keywords.keyword2 LIKE %s' therefore those 2 conditions would have to be true to make the statement true OR any of the other statements. if you do what angellll says and put the () around all of the ORs then those will do the logical OR and then REQUIRE the active as well.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now