Hi

It would be great if anyone could help me with a problem in mySQL.

I have 3 tables to describe attributes for a product database.

e.g.
attribute_type:
   +----+----------+------+
   | id | name     | unit |
   +----+----------+------+
   |  1 | height   | cm   |
   |  2 | width    | cm   |
   |  3 | diameter | cm   |
   +----+----------+------+

attribute_value:
   +----+----------+
   | id | value    |
   +----+----------+
   |  1 | 10       |
   |  2 | 20       |
   |  3 | 30       |
   |  4 | 222      |
   +----+----------+

attribute:
   +----+----------+----------+------------+
   | id | type_id  | value_id | product_id |
   +----+----------+----------+------------+
   |  1 | 1        | 1        |   21       |
   |  2 | 2        | 2        |   32       |
   |  3 | 2        | 3        |   40       |
   |  4 | 3        | 4        |   21       |
   +----+----------+----------+------------+

In a web form where I edit the product, there is also an attribute 
section where I would like to give certain attributes values specific 
for the product. The problem is when I associate values to attributes in 
one product, the same attribute in other products is hidden (not in the 
result of the query). Therefore I would like to list all attribute_types 
for each product regardless if there are values assigned or not.

I used the following query and I think there must be something wrong:

SELECT         at.name, av.value, at.unit,  at.id, a.product_id
FROM            attribute_type at
LEFT OUTER JOIN     attribute a on (at.id = a.type_id)
LEFT OUTER JOIN     attribute_value av on (av.id = a.value_id)
WHERE         (a.product_id = 21 OR a.product_id IS NULL OR a.value_ID 
IS NULL OR a.type_ID IS NULL)

regards,
  Andreas


-----------------------------------------
Andreas Habereder
private: [EMAIL PROTECTED]
mobile: +49 172 838 7771
-----------------------------------------


---------------------------------------------------------------------
Before posting, please check:
   http://www.mysql.com/manual.php   (the manual)
   http://lists.mysql.com/           (the list archive)

To request this thread, e-mail <[EMAIL PROTECTED]>
To unsubscribe, e-mail <[EMAIL PROTECTED]>
Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php

Reply via email to