Unix Technical Forum

AND-conjunction of rows

This is a discussion on AND-conjunction of rows within the MySQL General forum forums, part of the MySQL category; --> Hi list, I have three tables: product (ID, name) product2attribute (ID, product, attribute) attribute (ID, name) Product <-> Attribute ...


Go Back   Unix Technical Forum > Database Server Software > MySQL > MySQL General forum

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 02-27-2008, 09:31 PM
=?iso-8859-1?Q?Andr=E9_H=E4nsel?=
 
Posts: n/a
Default AND-conjunction of rows

Hi list,

I have three tables:

product (ID, name)
product2attribute (ID, product, attribute)
attribute (ID, name)

Product <-> Attribute is an n:m relation, so one product can have two or
more attributes and of course there can be many products with an attribute.

I want to select alle products that have attribute A and attribute B.

The only query that came to my mind was something like SELECT * FROM product
WHERE EXISTS (SELECT * FROM product2attribute WHERE attribute = ...) AND
EXISTS (SELECT * FROM product2attribute WHERE attribute = ...).

Is this the correct and only query to accomplish that?

Regards,
André

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 07:13 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com