mysql - create single query to fetch data from tables as seperate rows -


i thinking if there better way query product, product options , product option choices database

my database structure like:

product table (product_id, product_name) product_options table (option_id, option_name, product_id) product_optionchoices (choice_id, choice_name, option_id) 

i want single query return product , options in seperate rows like:

 -------------------------------------------------------------------------------- | product_id | product_name | option_id | option_name | choiceid | choice_name | | 1          | shoes        |           |             |          |             | | 1          |              | 1         | choose color|          |             | |            |              | 1         |             | 1        | red         | |            |              | 1         |             | 2        | blue        | -------------------------------------------------------------------------------- 

right using 3 sepearte queries product, product option , product_optionchoices , appending query using queryaddrow in coldfusion.

thanks

maybe solution helps if don't it.
returns want (updated).

select  p.product_id, p.product_name, '' option_id, '' option_name, ''  choiceid, '' choice_name `product` p union select  pr.product_id product_id, '' product_name, o.option_id, o.option_name, '' choiceid, '' choice_name `product_options` o inner join product pr on pr.product_id = o.product_id union select  '' product_id, '' product_name, op.option_id option_id, '' option_name, c.choice_id, c.choice_name `product_optionchoices` c inner join product_options op on op.option_id = c.option_id 

Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -