Results 1 to 5 of 5
Apr 4, 2011, 11:39 #1
- Join Date
- Apr 2007
- 0 Post(s)
- 0 Thread(s)
Querying two tables and certain columns?
Hi, wondering if anyone can kindly help please
After some help with a business search I have on a business directory. In the search you can either search for a company name ie:
Gregs Bar & Restaurant
Or a Business type ie:
And in my database I have a businesses table:
And a categories table:
So what I want to do is run a query which will query these two tables which I do like so.
SELECT * FROM businesses WHERE businesses.name = 'Fast Food' UNION SELECT * FROM categories WHERE categories.name = 'Fast Food'
- Take Away – as it falls into the same category as fast food
- Quick Bites – as it falls into the same category as fast food
(As they are all kind of the same thing)
So for example I want my search to :
1) Query the two tables for what the search term ie: Fast Food
When it finds Fast Food in the categories table look in the also_falls_into_category column of this table for Fast Food (piped separated)
2) Then explode on the pipes and continue with the query and output all the businesses in the businesses table where any of the pipe separated values are matches in the falls_into_category column. So in effect when you search for fast food, you also get results returned for take away and quick bites.
Can anyone help please?