Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What should be PHP/MySQL query for the following requirement?

It is a shopping cart, where user can add product to watchlist. Have a seprate page of User's watchlist where all product apepears that has been added to watchlist by that particular user. product_images table is separated from product table since 1 image can have multiple images.

MySQL Tables

Table "product" :
    pid(pk),name,price, etc...

Table "watchlist" :
    wid(pk),pid(fk),userid(fk)

Table "p_images" :
    image_id(pk),pid(fk),image_name

I want to fetch all information from product table and only 1st image of that particular product from p_images table. product should be fetch by pid in watchlist table.

like image 929
Mahendra Avatar asked Dec 05 '25 02:12

Mahendra


1 Answers

select * from product p
inner join p_images i on p.pid = i.pid
where p.pid = 1
group by p.pid
order by image_id
like image 163
juergen d Avatar answered Dec 06 '25 15:12

juergen d



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!