SELECT *
FROM Service
WHERE cusId='$cusId'
  AND serviceType IN (1,2)
ORDER BY date DESC LIMIT 2

我想要最后一个serviceType为1和2的服务记录,当我在查询中使用这个脚本时,我得到两行serviceType为1的服务,但是我想要两个serviceType为1和2的记录,对不起我的英语

最佳答案

(select * from Service
where cusId='$cusId'
and serviceType = 1
order by date desc limit 1)

UNION

(select * from Service
where cusId='$cusId'
and serviceType = 2
order by date desc limit 1)

10-08 03:49