开发者社区 问答 正文

mysql中in关键字查询时的问题? 400 报错

mysql中in关键字查询时的问题? 400 报错 select 
       eduresource.*
    from 
    eduresource 
    where 1=1
    and
        eduresource.resourcecode in
    (
       select downupload.resourcecode form downupload where
       downupload.usercode=? and downupload.opcode=?
       and downupload.delete_flg=0   <!-- 如果这里查出的没数据,会出错,有什么办法-->
    )
    and
        eduresource.delete_flg=0
    order by
        eduresource.createdate
    limit
       0,18

展开
收起
爱吃鱼的程序员 2020-06-05 12:43:35 534 分享 版权
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    之前也遇到过类似的问题,就是in关键字指定的范围没有数据,会出错######改用exists呢######不行######用join 链接查询过滤一下算了######我是这么做了,但是现在我就想知道,这种情况有解决办法吗######

    引用来自“抓瓦工人”的评论

    用join 链接查询过滤一下算了

    mysql IN不起来

    它是软的

    ######??????######

    你那会报什么错? 这个SQL不应该报错. 只会返回返回 empty set 而已. 我测试这个SQL是没问题的:

    select * from test where id in (select id from test where id = -1);



    ######不会报错. mysql v5.7.10######

    引用来自“hao5ang”的评论

    你那会报什么错? 这个SQL不应该报错. 只会返回返回 empty set 而已. 我测试这个SQL是没问题的:

    select * from test where id in (select id from test where id = -1);



    select 
           eduresource.*
        from 
        eduresource 
        where 
        eduresource.resourcecode in
        (
           select downupload.resourcecode form downupload where
           downupload.usercode='0' and downupload.opcode=0
           and downupload.delete_flg=0  
        )


    [Err] 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 'downupload where
           downupload.usercode='0' and downupload.opcode=0
          ' at line 8
    ######你SQL是这么写的? 括号里面 from 写成了 form吧.
    2020-06-05 12:43:50
    赞同 展开评论