请教一个有关聚合函数MIN的SQL语句?
两个数据库表
1、商品种类信息表名为:sort
id sort
1 食品
2 家电
3 日用品
2、商品信息,表名为:info
id sort name price
1 3 味精 2
2 2 电视 1000
3 1 食用油 40
4 2 冰箱 1500
5 2 洗衣机 1000
……
注:id字段是主键且为自动递增
现在我想把商品种类为2(家电)且商品id最小的数据行读取出来
即把
id sort name price
2 2 电视 1000
读取出来,我写的sql语句为
select MIN(id),sort,name,price from info where sort='2'
可是却提示错误:
MySQL Error: 1140 (Mixing of GROUP columns (MIN(),MAX(),COUNT()...) with no GROUP columns is
illegal if there is no GROUP BY clause)
Session halted.
请问我该如何修改我的SQL语句?另外还想问问,听说对自动递增的主键不能进行MIN函数操作,那么我要
是想读取在相应条件下id最小的字段该怎么操作。