I have two tables Product and images.
The values in the two tables are given below
SELECT * FROM ProductTable
Structure is (Productid, Categoryid, ProductName)
1 1 Product1
2 1 Product2
3 2 Product2
4 2 Product3
5 2 Product4
SELECT * FROM ImageTable
Structure is (ImageID, ProductID, ImageName)
1 1 Image1
2 1 Image2
3 2 Image3
4 2 Image4
5 4 Image5
6 5 Image6
My query is :
SELECT ImageTable.ProductID, ImageName
FROM ImageTable
LEFT JOIN ProductTable ON ImageTable.ProductID=ProductTable.ProductID
GROUP BY ImageTable.ProductID, ImageName
The result is :
1 Image1
1 Image2
2 Image3
2 Image4
4 Image5
5 Image6
But I want the result as (i.e. the First Imagename of the Productid from the imagetable)
1 Image1
2 IMage3
4 Image5
5 Image6
ImageIdvalue? Because tables, by definition, do not have an order.