我有一个ip存储在数据库中作为unsigned int但是当我尝试运行这个select我得到一个语法错误。我试过以下两个版本。
SELECT `id`, INET_NTOA(`from`) AS from, INET_NTOA(`to`) AS to, `campaignid` FROM `customiplist` WHERE `campaignid` = 1
SELECT id, INET_NTOA(from) AS from, INET_NTOA(to) AS to, campaignid FROM customiplist WHERE campaignid = 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 'from, INET_NTOA(`to`) AS to, `campaignid` FROM `customiplist` WHERE `campa' at line 1
我觉得我疯了,因为所有的列名和表名都是正确的。
答案 0 :(得分:2)
FROM
和TO
是reserved keywords in MySQ L。如果您要使用它们,则必须将它们包装在刻度线中:
SELECT `id`, INET_NTOA(`from`) AS `from`, INET_NTOA(`to`) AS `to`, `campaignid` FROM `customipblocklist` WHERE `campaignid` = 1
老实说,这些都是列名的错误选择。如果可能,我建议更换它们。