SQL命令:哪裏是我的SQL代碼中的錯誤?
UPDATE table1
SET colOne=1
WHERE id EXISTS (
SELECT IF(col1=19,col2,col1) AS id
FROM table2
WHERE
(col3=19 AND col4='X')
OR
(col3=0 AND col4='Y' AND (col1=19 OR col2=19))
)
內SELECT
查詢單獨做工精細
SQL命令:哪裏是我的SQL代碼中的錯誤?
UPDATE table1
SET colOne=1
WHERE id EXISTS (
SELECT IF(col1=19,col2,col1) AS id
FROM table2
WHERE
(col3=19 AND col4='X')
OR
(col3=0 AND col4='Y' AND (col1=19 OR col2=19))
)
內SELECT
查詢單獨做工精細
UPDATE table1
SET colOne=1
WHERE id IN (
SELECT IF(col1=19,col2,col1) AS id
FROM table2
WHERE
(col3=19 AND col4='X')
OR
(col3=0 AND col4='Y' AND (col1=19 OR col2=19))
)
您的意思是使用=代替存在
UPDATE table1
SET colOne=1
WHERE id = (
SELECT IF(col1=19,col2,col1) AS id
FROM table2
WHERE
(col3=19 AND col4='X')
OR
(col3=0 AND col4='Y' AND (col1=19 OR col2=19))
)
即使我嘗試,但不工作 – Simon
,你也可以做到這一點
UPDATE table1
SET colOne=1
WHERE EXISTS (
SELECT IF(col1=19,col2,col1) AS id
FROM table2
WHERE
(col3=19 AND col4='X')
OR
(col3=0 AND col4='Y' AND (col1=19 OR col2=19))
)
查詢有什麼不正確? – Alex
我不知道,但它不工作,並有一個錯誤附近EXISTS – Simon
嘗試用'IN'替換'EXISTS' – Alex