Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

mysql query issue

Posted on 2009-05-18
3
Medium Priority
?
216 Views
Last Modified: 2012-05-07
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
Comment
Question by:michael789
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 2000 total points
ID: 24412826
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
 
LVL 3

Expert Comment

by:DABOMB
ID: 24419146
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this blog post, we’ll look at how ClickHouse performs in a general analytical workload using the star schema benchmark test.
By, Vadim Tkachenko. In this article we’ll look at ClickHouse on its one year anniversary.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…
In this fifth video of the Xpdf series, we discuss and demonstrate the PDFdetach utility, which is able to list and, more importantly, extract attachments that are embedded in PDF files. It does this via a command line interface, making it suitable …

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question