mysql - sql join query issue with three table -


i new mysql.here structure of db table.*how can join 3 table give results fourth table?

table product

id      name    category   user_id   1       abc     2             1 2       syz     3             1 

table categories

id      name 1       aaa 2       bbb 3       ccc 

table product_image

id      image       product_id 1       abc.jpg         1 2       xyz.jpg         1 

forth table result looks like

id      name      category_name           image  1      abc       aaa                    xyz.jpg 

please me solve this. tried not getting correct result.

select product. * , categories.name cat_name, product_image.image product_image `product` inner join categories on categories.id = product.category , `user_id`='1' inner join `product_image` on product_image.product_id = product.id order rand( ) limit 1 

editing part

we need 1 image product_image associated multiple image in according product_id

try one

select p.id, p.name , c.name category_name, i.image product p  inner join categories c  on c.id=p.category left join   (select image, product_id product_image order rand( ) limit 1  )   on i.product_id=p.id p.id=1 

Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -