如果有条件,则限制每个来自不同列的 1 个

Limit 1 of each from different column if conditions

有没有办法说,select 数据库中的 2 行,其中一列等于某项,或者一列等于其他项,但您希望每个相等条件各占一行?所以...

SELECT * FROM tableName WHERE colName = '1' OR colName = '2' LIMIT...

1,其中 colName =“1”,1,其中 colName =“2”。所以,每一个。

如果您有值,则使用 union all:

(select t.*
 from tablename t
 where colname = '1'
 limit 1)
union all
(select t.*
 from tablename t
 where colname = '2'
 limit 1)