A表   字段  a1 a2 a3
B表   字段  B1\B2\B3
其中  a1跟B1关联
A表的多条A1字段对应一条B表中的B1字段
如果:
select a.a1  from A ,B where A.A2=2 AND a.a1=b.a1 group by A.A1
数据显示正常,但是不能列出A表A3字段的内容
如果
select a.a1,a.a3  from A ,B where A.A2=2 AND a.a1=b.a1 group by A.A1
出错
请问,使用什么语句可以查询到
select a.a1  from A ,B where A.A2=2 AND a.a1=b.a1 group by A.A1  的结果并且查到A3字段的内容
分不多,谢谢
补充一下  A表的A3字段内容不一样,我希望查询出最新的一条

解决方案 »

  1.   

    select a1,max(a3)   --a3 最新看如何定义了,这个lz自己调整一下
    from A
    where exists(select 1 from B where A.a1 = b.b1)
    and a2 = 2
    group by a1
      

  2.   

    select a.a1  from A ,B where A.A2=2 AND a.a1=b.a1 group by A.A1
      

  3.   


    --此只是会显示一个a3列数据
    select a.a1,max(a.a3)
    from 
    (select * from A where A.A2=2)a  
    inner join b on a.a1=b.b1
    group by A.a1--不知道lz为什么使用group by,在你提供的sql中看不出使用的必要,除非lz未提供场景
    select a.a1,a.a3
    from 
    (select * from A where A.A2=2)a  
    inner join b on a.a1=b.b1
      

  4.   


    select a.a1,(select top 1 a3 from A w where w.a1= a.a1 order by xx desc)  from A a ,B b where A.A2=2 AND a.a1=b.a1 group by A.A1
    --看你以什么字会排序,修改xx处理