嗨,我想将我的registry_ug
表与基于registry_ug.type
....的第二个表连接起来。我想避免不必要的连接。
这是我的代码
SELECT ug.id , tbl.id FROM registry_ug ug
JOIN CASE ug.type
WHEN 1 THEN users
WHEN 2 THEN group_software
END
AS tbl
ON
ug.id = tbl.id
WHERE ug.id = $uid
对我来说似乎没问题,但我收到了这个错误
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 'CASE ug.type WHEN 1 THEN users WHEN 2 THEN g' at line 2
SELECT ug.id , tbl.id FROM registry_ug ug JOIN CASE ug.type WHEN 1 THEN users WHEN 2 THEN group_software END AS tbl ON ug.id = tbl.id WHERE ug.id = 55
*而且我不想将它加入所有可能的第二张桌子*