我正在試圖結合這些MySQL查詢,但沒有弄清楚它們的正確性。這裏是我希望結合得到單行sql語句的僞代碼。將同一個表的多個查詢合併到一個SQL語句中
$var1 = "abc"
$var2 = "def"
IF ($var1 IN (SELECT DISTINCT col1 FROM t1))
{
SELECT colA, colB, colC FROM t1 WHERE col1 = $var1 AND col2 LIKE '%$var2%'
}
ELSE
{
SELECT colA, colB, ColC FROM t1 WHERE col2 LIKE %$var1%
}
感謝
到目前爲止你有嘗試過什麼嗎? – hakre
我試過了'SELECT IF('$ var1'IN(SELECT DISTINCT col1 FROM t1),(colA,colB,colC),)從t1',但我迷失在if語句的流程中 – user1115729