[英]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.