I have a table

id - Product_Name - Price - image

Some value like :

1 - My Product A - 50 - mpa.jpg
2 - My Product B - 10 - mpb.jpg
3 - My Product A - 40 - mpc.jpg
4 - My Product C - 20 - mpd.jpg

i need product image of unique product based on minimum value. i am useing this query

SELECT id, Product_Name, MIN(Price), image FROM table GROUP BY Product_Name

It is showing right min price but the it is wrong, that's why i am geting image wrong, please help me to fix this

4 Years
Discussion Span
Last Post by mastermind2

Honestly, your query looks good to me. Unless, you made a mistake in referring to the image.

<img src="directory/<?php echo $row['image'];?>" />

should give you something like this

<img src="directory/mpb.jpg" />

remember you query looks for the minimum price for each Product_name and not the MIN of all prices. Still, this scenario will not create an image mismatched.

Edited by veedeoo: more info added


thanks for you reply i have solve this issue with sub query. thakns again

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.