数据为主子表结构返回的结果集是主表中的数据字段
条件是 子表中某个字段的值等于参数 的主表记录例如:
主表
 name age sex
 chen 20   F
 wang 21   W子表
 name  class 
 chen  chn
 chen  eng
 wang  chn如果输入查询条件:chn ,则返回主表的 两条记录,如果查询条件为 eng ,则只返回主表的 chen那条记录谢谢!

解决方案 »

  1.   

    declare @class varchar(100)
    set @class='eng'
    select * from [主表] a join [子表] b on a.name=b.name where b.[class]=@class
     ??
      

  2.   

    select * from  主表 where name  in
    (
    select  name from  子表 where class ='chn'
    )
      

  3.   

    select *
    from 主表
    where
      name in(select name from 子表 where class='chn')
      

  4.   

    select * from 主表 a where exists(select 1 from 子表 where name=a.name and class='chn')
      

  5.   


    select a.* from 主表 a ,子表 b
    where a.name=b.name and b.class='chn'
      

  6.   

    select * from 主表 a 
    where exists(select 1 from 子表 where name=a.name and class='参数')
      

  7.   

    select distinct a.name,a.age,a.sex from 主表 a ,子表 b where a.name=b.name 
    and class='eng'--可以等于你要查询的
      

  8.   

    这个错了
    --> 测试数据:[主表]
    if object_id('[主表]') is not null drop table [主表]
    create table [主表]([name] varchar(4),[age] int,[sex] varchar(1))
    insert [主表]
    select 'chen',20,'F' union all
    select 'wang',21,'W'select * from [主表]
    --> 测试数据:[子表]
    if object_id('[子表]') is not null drop table [子表]
    create table [子表]([name] varchar(4),[class] varchar(3))
    insert [子表]
    select 'chen','chn' union all
    select 'chen','eng' union all
    select 'wang','chn'select a.* from [主表] a
    join [子表]  b on a.name=b.name  
    where b.class='chn'
    /*
    name age         sex
    ---- ----------- ----
    chen 20          F
    wang 21          W(2 行受影响)*/
      

  9.   

    select *
    from 主表
    where
      name in(select name from 子表 where class='chn')
      

  10.   

    select 
      *
    from 
      主表
    where
      name 
    in
      (select name from 子表 where class='chn')
      

  11.   

    为什么vb.net版总是升级啊  晕拉拉