mysql - sql select in relation many-to-many not works as expected -


i have following tables in relation many-to-many:

table product: prd_cod (pk) cat_cod (fk) prd_nome   table description_characteristic: prd_cod(fk) id_characteristic(fk) description  table characteristic: id_characteristic(pk) name 

we suppose cat_cod 1, show data this:

i have done select below solve problem:

select p.prd_cod,p.prd_name,c.name_characteristic,dc.description product p,description_characteristic dc, characteristic c p.prd_cod = dc.prd_cod , dc.id_ccharacteristic = c.id_characteristic , p.cat_cod = 1 

but data shown way:

prd_cod  prd_name   name_characteristic  descript     1          pen        color            pink         1          pen        manufacturer     kingston     1          pen        type                 brush   1          pen        weight               0.020 

i want show result way:

prd_cod  prd_name   name_characteristic  descript  name_characteristic  descript   1          pen        color            pink      type                 brush   2          pen-drive  manufacturer     kingston  weight               0.020 

i can not select solve please need thank all

select values want categories left join product on product.cat_cod=categories.cat_cod left join description_characteristic on product.prd_cod = description_characteristic.prd_cod left join characteristic on description_characteristic.id_characteristic=characteristic.id_characteristic categories.cat_cod = "1"; 

you need put tablename.column select fields exist in more 1 table.

(i assumed categories table called categories)


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -