1."select * from 记录表 where 编号=1 and 编号=34 and 编号=56 and 编号=72 and 编号=41 and 编号=..." 如果有很多个条件,上面的SQL语句效率编写效率太费劲了!请教合理的写法. 2.如果条件在另一张表的select 查询结果的“联接编号”字段里,正确的写法应该是怎样的? 
"select * from 记录表A where 编号=(***另一张表的select 查询结果的“联接编号”***) "

解决方案 »

  1.   


    1."select * from 记录表 where 编号=1 and 编号=34 and 编号=56 and 编号=72 and 编号=41 and 编号=..." 
    select * from 记录表 where 编号 in (1,34,56,72)
    select * from 记录表A where 编号=(***另一张表的select 查询结果的“联接编号”***) select * from 记录表A where 编号 in (select 联接编号 from table ) 
      

  2.   

    1."select * from 记录表 where 编号=1 and 编号=34 and 编号=56 and 编号=72 and 编号=41 and 编号=..." 如果有很多个条件,上面的SQL语句效率编写效率太费劲了!请教合理的写法. 这个语句不返回记录,可以如下简化
    select * from 记录表 where 1=2
      

  3.   

    2.如果条件在另一张表的select 查询结果的“联接编号”字段里,正确的写法应该是怎样的? 
    select * from 记录表A where 编号 in(select 联接编号 from 另一张表)
      

  4.   

    1."select * from 记录表 where 编号=1 and 编号=34 and 编号=56 and 编号=72 and 编号=41 and 编号=..."   
      你能查出来?
    2.
       --确保子查询结果只有一行
       select * from 记录表A where 编号=(select 联接编号 from b where 联接编号=记录表A.编号)
      

  5.   

    select * from 记录表A where 编号IN(select 联接编号 from b where 联接编号=记录表A.编号)
    你们神经病,子查询结果集能用=来连接,老师教你们的放屁眼里了吗?
      

  6.   

    我有个问题,这里子查询里已经联接编号=记录表A.编号,那么主句中这个编号IN好像没有什么意义了?
    个人对这样语句不是很理解,哪位可以解释一下吗?楼主的可以用exists字句select * from 记录表A where exists (select 联接编号 from b where 联接编号=记录表A.编号) 
      

  7.   


    1.select * from 记录表 where 编号 in (1,34,56,72) 2.select * from 记录表A where 编号 in (select 联接编号 from 另一张表 )