SQL查询内部联接错误

时间:2013-03-22 07:07:36

标签: sql-server inner-join

我正在处理一个SQL查询请这个显示此错误

  

Msg 116,Level 16,State 1,Line 2
  当未使用EXISTS引入子查询时,只能在选择列表中指定一个表达式。

这是查询

select 
   *,
   (select top 1 * 
    from tbl_Renewal 
    where supid = b.S_id 
      and Payed = 1 
    order by 
      renewalid desc) as result 
from 
    tbl_SuperAdmin as b 
inner join 
    tbl_Renewal as c on b.S_id = c.supid

请检查并给我解决方案

此实际任务的任何其他解决方案

请找到下面的任务简要说明

表1 'tbl_SuperAdmin'已提交

数据如示例

s_id name age gtc.......
1     abc  23 .........
2     cda  42 ..........

另一张表{2} 'tbl_Renewal'

renewalid  renname date supid   Payed etc......
1          first   -     1        1    ........
2          first   -     2        1    ........
3          second -      1        0     ........
4          second -      1        1     ........
5          third-        1        1     ........

感谢 pradeep

2 个答案:

答案 0 :(得分:1)

您不能在单列值中添加*,

查询应该是这样的

select 
       *,
       (select top 1 COLUMNNAME from tbl_Renewal where supid=b.S_id and Payed=1) as result 
from tbl_SuperAdmin as b inner join tbl_Renewal as c on b.S_id=c.supid

答案 1 :(得分:0)

将其缩短到sql以下

 select top 1 a.*,b.*

 from tbl_Renewal a inner join tbl_SuperAdmin as b

 on b.S_id=c.supid where a.Payed=1 order by b.renewalid desc