select * from table where id in (select * from table2)
我如果想用这里in表示id=子查询
如果我想用一个string 例如name like 子查询
那应该怎么写查询语句吗?有这种like 匹配子查询的方式吗?谢谢各位

解决方案 »

  1.   

    你的子查询返回的是一个结果集,不能用  =   或者  like  除非你的子查询返回的是一条记录,那样可以用 = 
      

  2.   

    select * from tablename where id in (select id from table2)
      

  3.   

    select * from tbName1 as A
    where exists(select 1 from tbName2 where id=A.id)
      

  4.   

    但是in 替代了=的作用,有没有什么符号能替代like 实现匹配子查询呢
      

  5.   

    select * from tablename 
    where id in (select distinct id from table2)
      

  6.   

    select * from table where id in (select * from table2 where name like '%')
    id in 等于id =
    子查询返回N个结果时用in
    子查询返回1个结果时用=
      

  7.   

    对,我现在想问的是
    in 相对与=
    ?  相对于like?  
    如果没有的话,那只有用exists来做了
      

  8.   

    exists(....)
    这个子句里面恐怕还得用like