-
Correct mysql query?
Hi, I have 3 tables - 'categories' just stores the name of my clients categories. 'business' stores info about businesses and 'businesscategories' has the id of businesses and categories - so in other words a business could have any number of categories.
If I wanted to find only those businesses where category=$clients-choice AND businessname=$whatever, what is the correct mysql query for that?
-
Re: Correct mysql query?
probably something like this:
Code:
select *
from categories c
inner join businesscategories bc on c.id = bc.categoryid
inner join businesses b on bc.businessid = b.id
where c.categoryname = $selection and b.name = $otherselection
Although as I think about it, shouldn't filter based on text like that... unless you're allowing wildcards in the selection... but if they are limited to only what's in the db...
Code:
select *
from businesses b
inner join businesscategories bc on b.id = bc.businessid
where c.id = $selection and b.id = $businessidselection
-tg
-
Re: Correct mysql query?
Thank you sir, I will try that;)