在 SQL SERVER ,ACCESS等数据库中可以这样调用:
select * from tableA where id in (select distinct id2 from tableB where type='测试')经过测试发现
MYSQL 可以使用 select * from tableA where id in (2,3)但是就是不能使用上面的第一个SQL语句
也就是说,好像 MYSQL 中的 in 语法只能是固定的,不能用动态查询出来的感觉很不方便请问有没有什么解决方法?谢谢

解决方案 »

  1.   

    不会吧,MYSQL版本,5.1可以支持上述语句。
      

  2.   

    try:
    select a.* from tableA a 
    inner join
    (select distinct id2 from tableB where type='测试') b
    on a.id=b.id2
      

  3.   

    or
    select a.* from tableA a
    left join
    (select distinct id2 from tableB where type='测试') b
    on a.id=b.id2 where b.id2 is not null
      

  4.   


    select a.* from tableA a 
    inner join 
    (select distinct id2 from tableB where type='测试') b 
    on a.id=b.id2

      

  5.   

    你报的什么错误?MySQL从4.1开始就支持你的语句了。
      

  6.   

    呵呵,同意楼上的,mysql可以这么用,不过,说实际的,效率确实是不怎么样。
    建议还是用 inner join ,但是要控制好数据输出,否则输出的结果集可能不是你想象中的。
      

  7.   

    我的版本确实太低了
    本机上存的,看是MYSQL就装了,后来看一下原来是老古董的3.XXX
    呵呵
    多谢各位