2014-09-24 158 views
1

我收到錯誤子查詢返回多個值 這裏是我的查詢子查詢返回多個值

SELECT d.Description ,s.Version , d.UtiPrefix , d.UTI , d.PrimaryAC , s.ReportingObb , s.ReportingObb , d.LEI , d.LEI_Countp , d.LEI , s.ReportingDeleg ,d.Curr , c.Trade_Party_Domicile ,c.LEI_SGR 
     , Price =(select Price 
        From Price 
        inner join Derivatives 
        on Derivatives.UTI = Price.UTI) 
FROM Derivatives as d 
INNER JOIN Settings as s 
ON d.LEI_SGR = s.LEI_SGR 
INNER JOIN Clients c 
ON d.LEI_SGR = c.LEI_SGR 

回答

2

使用相關子查詢

Price =(select Price From Price p WHERE d.UTI = p.UTI) 
+0

我認爲你有後向 – Paparazzi 2014-09-24 14:03:52

+0

@Blam沒關係 – Mihai 2014-09-24 14:04:26

+1

謝謝你對我有用。 – Dev 2014-09-24 14:05:30

1

我懷疑這返回多一行

(select Price 
    From Price 
    inner join Derivatives 
    on Derivatives.UTI = Price.UTI) 

你爲什麼要混合子查詢和連接?

SELECT d.Description ,s.Version , d.UtiPrefix , d.UTI , d.PrimaryAC , s.ReportingObb 
    , s.ReportingObb , d.LEI , d.LEI_Countp , d.LEI , s.ReportingDeleg ,d.Curr 
    , c.Trade_Party_Domicile ,c.LEI_SGR 
    , p.Price 
FROM Derivatives as d 
INNER JOIN Settings as s 
    ON d.LEI_SGR = s.LEI_SGR 
INNER JOIN Clients c 
    ON d.LEI_SGR = c.LEI_SGR 
INNER JOIN Price p 
    ON p.UTI = d.UTI