donglanfu5831 2014-04-09 02:21
浏览 64
已采纳

用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-09 02: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.

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

报告相同问题?

悬赏问题

  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用
  • ¥15 微信小程序协议怎么写
  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?