select T2.id,T2.name 
from Table1 as T1 
     right join 
     Table2 as T2
on T1.name=T2.name
where T2.name='aaa'
好长时间没写sql语句了,好象是这样的吧
你试试看。

解决方案 »

  1.   

    老兄要加强后台的学习呀
      select name
      from table1 
      where id = 'aaa'
    UNION 
       select name
      from table2 
      where id = 'aaa'  
       
      

  2.   

    Select * from table1,table2 Where (table1.name='aaa')or( table2.name='aaa')
      

  3.   

    yoic():
       哦,不要求 T1.name=T2.name, T1 和 T2没有关联。shuixin13(心帆) :
       table2中其他字段(table1没有的)不能选出。
      

  4.   

    Select table1.id,table1.name,table2.id,table2.name,table2.now_time from table1,table2 Where (table1.name='aaa')or( table2.name='aaa')
      

  5.   

    select table1.id,table1.name,table2.now_time from table1,table2 where table1.name = table2.name and table1.name = 'aaa'
      

  6.   

    select t1.id as t1_id, t1.name as t1_name 
           t2.id as t2_id, t2.name as t2_name
    from table1 as t1 
    inner join table2 as t2
    on t1.name=t1.name
    where t1.name='aaa' or t2.name = 'aaa'
      

  7.   

    table1 的记录
    1   aaaa
    2   bbbb
    3   cccc
    4   ddddtable2 的记录
    1   qqqq  2002-2-2
    2   wwww  2002-2-2
    3   aaaa  2002-2-2要求得到的结果如下:
    1、如果查询 name='bbbb'的就应该返回 table1 中的
       id  name
       1   bbbb2、如果查询 name='qqqq'就应该返回 table2 的
       id  name 
       1   qqqq3、如果查询 name='aaaa' 就应该返回 table1 和 table2 中的
       id  name
       1   aaaa
       3   aaaa要求只对 table1 和 table2都有的相同类型和名称的字段查询。这种 SQL 如何写?