SELECT place.PlaceID, place.Location, place.PlaceName, place_img.ImgPath FROM place LEFT JOIN place_img ON place.PlaceID = place_img.PLACE_PlaceID GROUP BY place_img.PLACE_PlaceID The above SQL query works fine if I used it without the GROUP BY clause. I don't understand what the problem is with the GROUP BY clause.
If I run the query without using GROUP BY clause:
But if I run the query with the GROUP BY clause, then I get:
Why is this happening?
GROUP BYhere in the first place.GROUP BYis mainly useful if you want to take aggregates (e.g. sums, averages) over groups of records. If you are already happy with the first version of your query, then there is no need to spruce it up by addingGROUP BY.placeandplace_img. there are more than 1 record inplace_imgtable for one PlaceID (PlaceID is the primary key onplacetable and it's the foreign key of theplace_imgtable). I need to select only one image from theplace_imgtable for each record in theplacetable.