mysql - Query multiple rows that leads to one row in other table -
i'm noob @ making mysql queries couldn't work done. hope guys know answer question.
i want make options products. if have black t-shirt, tanktop model , diamonds on it. must have black t-shirt tanktop model , diamonds row. want make this:
table: product_option -------------------------------- product_option_id name product_combination_id 1 black 1 2 diamond 1 3 tanktop 1 4 option 2 5 option 2 table: product_combination -------------------------------- product_combination_id name 1 black tanktop diamonds
so question is. possible query product_options , product_combination row out of it?
i hope guys know answer question! thank time :)
edit:
i think question general , want ask more specific.
let's say. have shop clothes. have product (let's t-shirt). , there couple of options choose from.
like this:
color: - black - red - orange size - large - xtra large - medium - small accessoire: - diamonds - printed - swarovski
let's want buy black / xtra large t-shirt diamonds on it. product_combination
must black/large/diamonds row. think need foreign table many many relation. product_combination_option table columns:
product_combination_option - product_combination_option_id - product_combination_id - product_option_id
but again. how can query when chooses black / xtra large diamonds , find product_combination
is.
i hope i'm bit clearer now. sorry updated question late! appreciate answers much!
i think looking joining tables, can pick combination based on product have.
so, that, query can be
select * product_option inner join product_combination using(product_combination_id);
this joins 2 tables. can replace * list of attributes want display/fetch.
Comments
Post a Comment