我有三個MySQL的InnoDB表: 債務人 公司 個人MySQL的中頻SELECT
現在我想找到有關債務人的信息。 以下SQL不起作用,任何人都可以幫我編寫工作SQL嗎?
SELECT
d.id,
d.type,
i.name
FROM
debtors AS d
IF d.type = 'c' THEN
INNER JOIN
companies AS i ON (i.debtor_id = d.id)
ELSE THEN
INNER JOIN
private_individuals AS i ON (i.debtor_id = d.id)
WHERE
d.id = 1
錯誤:
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF d.type = 'c' THEN INNER JOIN companies AS i ON (i.debtor_id = d.i' at line 7
提前感謝!
您是否嘗試過狩獵MySQL文檔中'IF'?例如。爲'IF'找到正確的語法?你正在嘗試做那些在MySQL中不可行的東西(可能完全在SQL上)。 – Romain