![](/img/trans.png)
[英]In mySql, how can I ask: select this row from table 1 where x = column in table 2 or no rows in table 2
[英]Select * from table WHERE `column` = x if `column` != -1
我需要做出选择,
Select * from table WHERE column = x if column != -1
但我暂时不知道。
任何人都知道或做过这样的事吗?
谢谢。
你也应该这样写
Select * from table
WHERE
1 = case when column != -1 then
case when column = x then 1 else 0 end
else 1 end
您可以在where子句中使用大小写。 同样,您可以添加更多条件条件,例如,
Select * from table
WHERE
1 = case when column != -1 then
case when column = x then 1 else 0 end
else 1 end
AND
1 = case when column1 [conditional operator] value then
case when column1 = xx then 1 else 0 end
else 1 end
这只是一个示例,您可以将更多的条件条件整合在一起,即使您可以在其他部分添加更多的情况。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.