Solved

mysql query issue

Posted on 2009-05-18
3
210 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
3 Comments
 
LVL 142

Accepted Solution

by:
Guy Hengel [angelIII / a3] earned 500 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

Use Case: Protecting a Hybrid Cloud Infrastructure

Microsoft Azure is rapidly becoming the norm in dynamic IT environments. This document describes the challenges that organizations face when protecting data in a hybrid cloud IT environment and presents a use case to demonstrate how Acronis Backup protects all data.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
simplest php form 3 79
RDBMS and No sql database 4 58
AWS EC2 & RDS Instance 5 36
some keys in my laptop is not working. any suggestion 6 32
This article will show, step by step, how to integrate R code into a R Sweave document
If you’re thinking to yourself “That description sounds a lot like two people doing the work that one could accomplish,” you’re not alone.
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…
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

809 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