2013-03-22 145 views
0

我在一個SQL查詢工作,請這個人是出 只有一個表達式可以在選擇指定此錯誤SQL查詢內部聯接錯誤

消息116,級別16,狀態1,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 .......... 

'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  ........ 

感謝 普拉迪普

回答

1

你不能把一個*單獨列的值另一個表2,

查詢應是這樣的

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 
+0

離開它從tbl_Renewal這個選擇頂部1 COLUMNNAME其中supid = b.S_id和所許= 1給波紋管解決方案,如果把columname也重複來了 – 2013-03-22 07:26:48

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