table1 
id name level 
1 张三 101 
table2 
id name category 
101 高手 A 
201 高高手 B 通过table1中id查出如下显示 
table1.id table1.name table1.level table2.name table2.category
1 张三 101 高手 A请看清楚我的需求:根据 table1 中 id 查的如上结果 另外 table1 中字段非常多 请用* 代替 

解决方案 »

  1.   


    select *
    from table1 a join table2 b on a.id = b.id
      

  2.   

    select table1.id ,table1.name ,table1.level ,table2.name ,table2.category
    from table1 left join table2 on table1.level = table2.id
      

  3.   


    select *
    from table1 a join table2 b on a.[level] = b.id
    1楼写错了。
      

  4.   

    有必要就把join换成left join 。
      

  5.   

    declare @id int
    set @id=5  --这儿输入你要查的ID
    select table1.*,table2.name,table2.category
    from table1 inner join table2 on table1.level=table2.id
    where table1.id=@id
      

  6.   

    select a.*,b.name,b.category
    from table1 a left join table 2 b on a.level=b.id
      

  7.   


    你们都忽略 一个问题  结果集是根据 table1.id 查询出来的 
      

  8.   

    当然...100分哪~~~不过,也不能当饭吃,帮忙而已.昨天看到报道,一菜场边一老头因为摔了一跤,躺在那儿一个小时没人扶而窒息身亡,真的感叹,社会上像 CSDN 里这样热心肠的人太少了...
      

  9.   

    准确的答案应该是:
    select *
    from table1 a join table2 b on a.level = b.id and a.id = ?