SELECT Dish.DishID, DishImage.ImagePath, Dish.DishName
FROM Dish LEFT OUTER JOIN
DishImage ON Dish.DishID = DishImage.DishID
WHERE (Dish.Online = 1)
查询结果
9 /9/s10042007171459.jpg DishName5
10 /10/s10042007171705.jpg Honey Roast Pork
11 /11/s10042007171801.jpg Curry Chicken
12 /12/s10042007171918.jpg Pork with Onions and Ginger
12 /12/s10042007172007.jpg Pork with Onions and Ginger
13 /13/s05042007164747.jpg Crispy Chilli Beef
14 /14/s10042007172237.jpg DishName14
15 NULL Egg Fried Rice
(所影响的行数为 11 行)
能不能相同id的只显示一条记录呢,我只想要一个图片而已,比如
9 /9/s10042007171459.jpg DishName5
10 /10/s10042007171705.jpg Honey Roast Pork
11 /11/s10042007171801.jpg Curry Chicken
12 /12/s10042007171918.jpg Pork with Onions and Ginger
13 /13/s05042007164747.jpg Crispy Chilli Beef
14 /14/s10042007172237.jpg DishName14
15 NULL Egg Fried Rice
谢谢
------解决方案--------------------
SELECT Dish.DishID, max(DishImage.ImagePath), max(Dish.DishName)
FROM Dish LEFT OUTER JOIN
DishImage ON Dish.DishID = DishImage.DishID
WHERE (Dish.Online = 1)
group by Dish.DishID
------解决方案--------------------
一、加一distinct:
SELECT distinct Dish.DishID, DishImage.ImagePath, Dish.DishName
FROM Dish LEFT OUTER JOIN
DishImage ON Dish.DishID = DishImage.DishID
WHERE (Dish.Online = 1)
------解决方案--------------------
同意:gjz_1209(龙行天下--结婚好累!)
------解决方案--------------------