Welcome to WebmasterWorld Guest from 54.198.118.102

Forum Moderators: open

Message Too Old, No Replies

MYSQL Join problem

     
9:05 pm on Feb 9, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2005
posts: 143
votes: 0


Hello,

Here's a problem that I've been wrestling with and googling for about 12 hours now. I hope I can explain myself adequately.

I have two tables set up like this:

table: products

| product_name | brand_name |
=============================
| product a | company x |
| product b | company y |

table: tags

| product_name | tag |
=============================
| product a | feature 1 |
| product a | feature 2 |
| product b | feature 2 |

So table 'tags' contains features about the products while 'products' contains other information on the products. Unfortunately I can't have the two in one table.

What I'm struggling with is making an SQL call which says something like:

"join the tables and show all products which have feature 1 and feature 2"

Here's what I've been trying:

SELECT tags.product_name, brand_name, tag
FROM products JOIN tags
ON products.product_name = tags.product_name
WHERE tag = 'feature a' AND tag = 'feature b'
ORDER BY product_name ASC

The problem I have is I can't find how to choose TWO columns from the tags table.

I hope I've explained my problem and thank you for any help you can give a tired coder.
10:03 pm on Feb 9, 2010 (gmt 0)

Full Member

5+ Year Member

joined:June 21, 2007
posts: 316
votes: 0


Hi,

Have you tried the following
<code>
SELECT pt.product_name, p.brand_name, pt.tag FROM products as p INNER JOIN tags as pt ON p.product_name = pt.product_nae
WHERE pt.tag IN('feature a','feature b')
</code>


Is that the kind of thing you're after?
10:04 pm on Feb 9, 2010 (gmt 0)

Full Member

5+ Year Member

joined:June 21, 2007
posts:316
votes: 0


Note: I've made a typo in the above on pt.product_nae should be product_name
12:49 pm on Feb 10, 2010 (gmt 0)

Junior Member

10+ Year Member

joined:May 7, 2005
posts:143
votes: 0


Hi Tommybs,

Thanks for the posts. I've got that sorted with your help. Much appreciated.
 

Join The Conversation

Moderators and Top Contributors

Hot Threads This Week

Featured Threads

Free SEO Tools

Hire Expert Members