SELECT(IF(IN query.
Posted
by Harold
on Stack Overflow
See other posts from Stack Overflow
or by Harold
Published on 2010-03-18T10:37:45Z
Indexed on
2010/03/18
10:41 UTC
Read the original article
Hit count: 250
mysql
There are 3 tables. Products, Options and Prod_Opts_relations. The latter holds product_id and option_id so i should be able to figure out which options are selected for any given product.
Now i want to retrieve all options from the options table where the value of an extra alias field should hold checked or unchecked depending on the existance of a mathing record in the relations table for a give product id.
Thus far i came up with this:
SELECT
IF(IN(SELECT id_option FROM prod_opt_relations WHERE id_product='18'),'y','n') AS booh
,optionstable.id AS parent_id
,optionstable.name_en AS parent_english
,optionstable.name_es AS parent_spanish
FROM product_options AS optionstable
WHERE 1
resulting in syntax errors.
Alas i just cannot figure out where things go wrong here
© Stack Overflow or respective owner