Select, Join, AS "Selected" if they are in a table -


i have 2 tables. 1 product_colors.. other bridge table product_colors_bridge.. bridge table contains productid , colorid..

i need stored procedure brings of colors , adds "selected" field statement.

tables
product_colors id, color

product_colors_bridge id, productid, colorid

colorid references product_colors.id

ideal result
id, color, productid, colorid, selected (this field must added using sql)

where selected field value either true or false...

well, without knowing db, standard sql query (not stored procedure) this:

select color, productid, colorid, case when productid null false else true end selected product_colors c left outer join product_colors_bridge pc on pc.colorid=c.id 

with left outer join left table records (colors) retained, , check directly in select clause if corrispondent color/product exists in db return 'selected' value.

hope helps!


Comments

Popular posts from this blog

php - Why I am getting the Error "Commands out of sync; you can't run this command now" -

linux - Does gcc have any options to add version info in ELF binary file? -

java - Are there any classes that implement javax.persistence.Parameter<T>? -