A表为商品表,
B表为sku表,(每个商品有多个sku(规格))
查询所有商品中并且每个商品中sku的价格为最小的整条数据
select
A.id,A.goodsname as title,A.norms,A.status as gstatus,A.imgurls,A.uppertime,A.downtime,A.createtime as gcreatetime,A.updatetime as gupdatetime, A.isteam,B.id as defaultsku,B.price as minprice,B.preprice
from A
INNER JOIN B on A.id=B.goodsid
where B.price = ( select min(B.price) from B where B.goodsid=A.id)
and A.status=1 and B.status=1
group by A.id
order by A.id desc
单表查询:
要id最小的一条,最简单的语句是:
select * from table order by id
如果一定要使用where条件,那么可以这样写:
select * from table where id=(select min(id) from table)