有一个查询:
select
CONCAT_WS(' ',column_1,column_2) as col
from table_1 as t1
inner join table_2 as t2 on t1.pk = t2.pk;
我想仅在colum_1!= colum_2时进行连接,否则只选择column_1。
是否有MySQL函数可以知道column_1 = column_2
?
答案 0 :(得分:2)
对两个备选方案使用case
语句:
select
case
when colum_1 != colum_2 then CONCAT_WS(' ',column_1,column_2)
else colum_1
end as col
from ...