donglanfu5831 2014-04-08 18:21
浏览 66
已采纳

用mysql选择使用inet_ntoa的SQL语法错误

I have an ip stored in the database as an unsigned int but when i try and run this select i get a syntax error. i have tried both versions below.

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

i feel like i'm going mad because all the column names and table name is correct.

  • 写回答

1条回答 默认 最新

  • duanlang1196 2014-04-08 18:23
    关注

    FROM and TO are reserved keywords in MySQL. If you're going to use them, you must wrap them in ticks:

    SELECT `id`, INET_NTOA(`from`) AS `from`, INET_NTOA(`to`) AS `to`, `campaignid`  FROM `customipblocklist` WHERE `campaignid` = 1
    

    Honestly, those are bad choices for column names. I recommend changing them if at all possible.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部