我有三个 MySQL InnoDB 表: 债务人 公司 私人
现在我想查找有关债务人的信息。下面的 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
提前致谢!