2014-06-29 57 views
-1

这是我的子查询,但它不工作:的Sql子查询不工作

SELECT  CommitmentLog.app_id, CommitmentLog.CommitAmt, CommitmentLog.CommitDate, 
    CommitmentLog.status, CommitmentLog.ConfirmDate, Appreg.uid, Appreg.SpillBy, 
    Appreg.spill, Appreg.Email, Appreg.pass, Appreg.intro_id, Appreg.app_id AS Expr1 
FROM CommitmentLog 
INNER JOIN Appreg ON CommitmentLog.app_id = Appreg.app_id 
where Appreg.app_id = 
(
    SELECT dbo.UIDFromApp_ID(Intro_id) as 'SponsorUserID', [app_id],[uid], [app_name], [Side], [doj] 
    FROM [v_Appreg] 
    WHERE ([Intro_id] = 1496) 
) 

提示错误:您正在使用MSSQL

Msg 116, Level 16, State 1, Line 4 
Only one expression can be specified in the select list when the subquery is not introduced with EXISTS. 
+2

是sql-server还是mysql? – Jens

+0

子查询不适用于多个领域...尝试单个字段 – sumit

回答

0

假设(错误看起来SQL-Serverish)而且你在子查询中寻找app_id,这样的事情应该是你追求的目标。

SELECT 
    CommitmentLog.app_id, 
    CommitmentLog.CommitAmt, 
    CommitmentLog.CommitDate, 
    CommitmentLog.status, 
    CommitmentLog.ConfirmDate, 
    Appreg.uid, 
    Appreg.SpillBy, 
    Appreg.spill, 
    Appreg.Email, 
    Appreg.pass, 
    Appreg.intro_id, 
    Appreg.app_id AS Expr1 

FROM CommitmentLog 
INNER JOIN Appreg 
    ON CommitmentLog.app_id = Appreg.app_id 
WHERE Appreg.app_id IN 
    (SELECT [app_id] FROM [v_Appreg] WHERE ([Intro_id] = 1496)) 

完全一样的错误说,试图使用IN子句时,你只能拥有一个子查询单个值。

+0

非常感谢你,它工作 –

0

由于错误消息告诉您只需要在子查询中检索一个值。

SELECT 
    CommitmentLog.app_id, 
    CommitmentLog.CommitAmt, 
    CommitmentLog.CommitDate, 
    CommitmentLog.status, 
    CommitmentLog.ConfirmDate, 
    Appreg.uid, 
    Appreg.SpillBy, 
    Appreg.spill, 
    Appreg.Email, 
    Appreg.pass, 
    Appreg.intro_id, 
    Appreg.app_id AS Expr1 

FROM 
    CommitmentLog INNER JOIN Appreg ON CommitmentLog.app_id = Appreg.app_id 

WHERE 
    Appreg.app_id = 
     (SELECT dbo.UIDFromApp_ID(Intro_id) as 'SponsorUserID' FROM [v_Appreg] WHERE [Intro_id] = 1496) 
0

错误消息告诉你到底发生了什么问题。您正在试图说

where appreg.app_id = 
(select dbo.UIDFromApp_ID(Intro_id) as 'SponsorUserID', [app_id], etc 

这是不明确的。您必须仅为该字段分配一个值。

一旦你对此进行了排序,你就会遇到另一个问题。如果你的子查询返回多于一行,它再一次含糊不清。你必须为此做点什么。细节取决于您的要求。