你试一下下面的查询。
1.SELECT Top N TableB.field1,TableB.field2,TableB.field3 
FROM TableA INNER JOIN TableB ON TableA.Number=TableB.Number.
2.SELECT DISTINCT TableB.field1,TableB.field2,TableB.field3 
FROM TableA INNER JOIN TableB ON TableA.Number=TableB.Number.

解决方案 »

  1.   

    好象不是这个意思。比如,TableA 中有这么一些人,Primary Key 是 Number,他们在 TableB 中有两个记录,每个记录都有相同的 Number,如何把他们列出来?
    ...
    Select @X=number from TableA
    Select @CX=count(*) from TableB where number= @X
    IF @CX=2 ...
    我现在是希望用一个 SQL 语句来实现。
      

  2.   

    给我加分哟。Select B.Number,B.* from TableB as B,TableA as A where B.number=A.number
      

  3.   

    SELECT * FROM TABLEB WHERE NUMBER=(SELECT NUMBER FROM TABLE A WHERE NUMBER='NUMBER')
    至于N可以由你取呀。
    呵呵,在oracle中是这样的,我没有sql server环境,呵呵,你试试行不行吧!
      

  4.   

    select * from tableA where (select count(number) as couNum from tableA where tableB.number =tableA.number)=N
      

  5.   

    上述在SQL Server(Transact SQL)中好使,在Access中不好使
    另请教:Access 的 SQL 是 ANSI SQL 吗?
      

  6.   

    powerbamboo 的方法我用过:
    select * from tableA where (select cnt= count(number) from tableA where tableB.number =tableA.number)=N 
    但我还有其他的条件,加上去之后,不符合条件的记录也一样出来。