select * from car where carbrand = 'bmw' limit 1
union
select * from car where carbrand = 'mercedez'
是否可以在不使用Union的情况下组合此查询?
答案 0 :(得分:5)
尝试
SELECT * FROM car WHERE carbrand IN ('bmw', 'mercedez') GROUP BY carbrand
编辑:
SELECT * FROM car WHERE carbrand IN ('bmw', 'mercedez') GROUP BY CASE WHEN carbrand = 'bmw' THEN carbrand ELSE car_id END
在上面的ELSE条件中查看car_id
,将其标记为相应的ID。