2 个表如下:A 表
-----------
pID      gID
ABC      G1
ABC2     G1
ABC3     G1
AD       G2
ABC      G2
ABC      G3B 表
-----------
gID     uID
G1      David
G3      Tom
G1      Tom希望当 B.uID = 'David' 时的查询结果为:C 表
-----------
pID
ABC
ABC2
ABC3谢谢!

解决方案 »

  1.   

    select a.pID from A as a, B as b where a.gID = b.gID and b.uID = 'David'
      

  2.   

    select A.pID from A inner join on(A.gID=B.gID)
    where B.uID = 'David'
      

  3.   

    SELECT a.pID FROM A WHERE a.gID IN
    (SELECT gID FROM B WHERE b.uID='David')
      

  4.   

    select A.pID from A inner join on(A.gID=B.gID)
    where B.uID = 'David'
    -------------------------------服务器: 消息 156,级别 15,状态 1,行 4
    在关键字 'ON' 附近有语法错误。
      

  5.   

    select pid from a where gid=(select gid from b where uid='david')
      

  6.   

    select a.pid from A a where a.gid=( select b.gid from B b where b.uid='David' )
    select a.pid from A a ,B where a.gid=B.gid and B.uid='David'
    这两个都行。