三张表:数据库中提供了[PM_ProductParts],[ PM_Product]数据,提供了一个查询字符串string chaxun; 
[PM_Product]中的字段C为名称。字段A是主键,同时也与[ PM_ProductParts]字段B互为外键。A表与B表是一对多关系。 举个例子 :A表是省份表,B表是城市表, 主键A为省份ID ,与B表中B所属省份ID互为外键。现在要查询这样一个条件的: [PM_Product]表中所有C=chaxun的记录,[ PM_ProductParts]表中B=A的所有的记录。
  

解决方案 »

  1.   

    ?没看明楼主的意思
    select * from A,B where A.A=B.B where A.C='chaxun'
      

  2.   

    select * from [PM_ProductParts] as a,[ PM_Product] as b 
    where a.a=b.b and a.c='chaxun'
      

  3.   

    select a.*,b.* from PM_ProductParts a inner join PM_Product b on a.A=b.B where a.C='chaxun'
      

  4.   

    select * from [PM_ProductParts a,[ PM_Product] b 
    where a.a=b.b and a.c='chaxun'
      

  5.   

    select
      b.* 
    from
      [PM_ProductParts] a,[ PM_Product] b
    where
      a.b=b.c
    and
      b.C='chaxun'
    and
      a.b='a'
      

  6.   


    --是否查询pr_productparts表查出B对应A且pm_product表中C=CHAXUN的记录
    select * from pm_productParts where B in (select A from pm_product where c='xhaxun')