Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with LIKE selection in query 2

Status
Not open for further replies.

electricphp

Programmer
Feb 20, 2008
71
US
I have this query:

"SELECT * FROM ads WHERE cats LIKE'%$find%'"

lets say that $find is "Wines and Cheeses"

for some reason, it is selecting records that only have "wines" in them, so it will select "wines and beers"

How can I change this query so it only selects records that have the full string "Wines and Cheeses" in them

 
yes it does, there is one other thing and since i have to reformat the whole db I may as well do it right.

There is another table called subcategories. This table is a subset of each individual category, so it references the categories table. So in reality I'm supposed to pick records that match the subcategories.

How should I modify the sql so it incorporates this other table, because in reality what I'm saying is select * from ads that match subcategories.

I don't think there will be any subcategories that will appear in more than one category, but I'm guessing to be thorough I should set it up to say select * from ads where category = "whatevercategories" AND subcategory = "whateversubcategories
 
How would i need to modify the following query

SELECT ads.*
FROM ad_categories
INNER
JOIN ads
ON ads.id = ad_categories.ad_id
WHERE ad_categories.cat_name = 'Wine and Cheeses'



If I had another table named ad_cities, that has the fields
"ad_id" and "city" in it, and has the same relashionships to the ads table as the ad_categories table has to the ads table?

And say I want to pull records that include wine and cheese and are in Boston
 
SELECT ads.*
FROM ad_categories
INNER
JOIN ads
ON ads.id = ad_categories.ad_id
INNER
JOIN ad_cities
ON ad_cities.ad_id = ads.id
WHERE ad_categories.cat_name = 'Wine and Cheeses'
AND ad_cities.city = 'Boston'


r937.com | rudy.ca
Buy my new book Simply SQL from Amazon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top