我想从userid上的Food表中选择数据,但是foodname应该是不同的。
我使用了以下查询
SELECT *
FROM Food
WHERE cfid IN (
SELECT distinct(foodname) FROM Food WHERE userid=234
);
但它返回一组空数据。
餐桌
cfid foodname userid brand
160 special chapati 234 homemade
161 chicken fry special 234 kfc
162 apple punch 234 homemade
164 pohapokri 234 homemade
165 pohapokri 234 homemade
167 besan gatte 234 home made
168 besan gatte 234 home made
169 pohapokri 234 homemade
172 chicken fry special 234 kfc
174 special chapati 234 homemade
175 special chapati 234 homemade
最佳答案
从您的评论中,在cfId上使用agroup by
和amin
select min(cfId), foodname, userid, brand
from food
group by foodname, userid, brand
--where userid=234
关于mysql - 多列的MySQL不同查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/30394376/