Avatar of Tony Pearce
Tony PearceFlag for United Kingdom of Great Britain and Northern Ireland

asked on 

Mysql Use two AND's to retrieve only records matching both

Hi,
I have a query that looks for matching criteria in two columns, when using this query either/or gets selected, I need it to only pick the records that match both??

SELECT ProdCAT1 FROM $tableName WHERE ProdCAT1 LIKE '%$siteword%' AND ProdSELECT LIKE '%$brandword%'

Any pointers? I can't use PHP, it must be done in the query...
MySQL ServerSQL

Avatar of undefined
Last Comment
Tony Pearce
SOLUTION
Avatar of Sean Stuber
Sean Stuber

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Tony Pearce
Tony Pearce
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Sorry, I typed question too quickly, what I mean is:

both conditions MUST be correct for the record to be returned, if either one is incorrect then it is not.

Or have I just got it totally wrong,

The query as is will return results even if second one does not....
ASKER CERTIFIED SOLUTION
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
Avatar of Tony Pearce
Tony Pearce
Flag of United Kingdom of Great Britain and Northern Ireland image

ASKER

Thats it, thank you all very much, changed to an exact = and no wildcards and all is fine in the world..
SQL
SQL

SQL (Structured Query Language) is designed to be used in conjunction with relational database products as of a means of working with sets of data. SQL consists of data definition, data manipulation, and procedural elements. Its scope includes data insert, query, update and delete, schema creation and modification, and data access control.

61K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo