0

得到旧

消息 512,级别 16,状态 1,第 1 行子查询返回超过 1 个值。当子查询跟随 =、!=、<、<=、>、>= 或当子查询用作表达式时,这是不允许的。"

当我尝试运行此脚本时出错:

SELECT  name_first,
        name_last
FROM person
INNER JOIN message
    ON person.person_id = (
        SELECT message.recipient_id 
        FROM message 
        WHERE message.filename = '1003-5ivGbUqIz80r0NwCl9kzWpDjYDit9L.mp3')

任何有关找出我做错了什么的帮助将不胜感激。

4

2 回答 2

3

您不需要有子查询。

SELECT DISTINCT name_first, name_last
FROM   person 
       INNER JOIN message 
         ON person.person_id = message.recipient_id  
WHERE  message.filename = '1003-5ivGbUqIz80r0NwCl9kzWpDjYDit9L.mp3'

DISTINCTSELECT子句中指定仅显示唯一的人名,假设它可以有多个消息。

于 2013-09-25T22:24:05.840 回答
0
you can use this type of sub query insted of Joins......

USE [FydaDB]
    GO
    /****** Object:  StoredProcedure [dbo].[CountryManagerReport]    Script Date: 5/25/2018 2:12:42 AM ******/
    SET ANSI_NULLS ON
    GO
    SET QUOTED_IDENTIFIER ON
    GO
    ALTER PROCEDURE [dbo].[CountryManagerReport] 
        @FromDate datetime,
        @Todate datetime,
        @countryId int
    AS
    BEGIN
    Select FirstName+ ' ' + MiddleName+ '' +  LastName as FullName ,Email,CNIC,((select CountryCode from Country where ID=FydaAdmin.CountryId)+ '-' +(select PhoneNo from Contacts where FydaAdminId=FydaAdmin.ID)) as Mobile,
    (ZipCode+ ' ,' +[Address]+ ' ,' + (select Name from City where ID=FydaAdmin.CityId )+ ', ' +(select Name from States where ID=FydaAdmin.StateId )+ ', ' +(select Name from Country where ID=FydaAdmin.CountryId)
     ) as [Address]
     from FydaAdmin where CreatedDateTime  BETWEEN  @FromDate  and @Todate or CountryId=@countryId 
    END
于 2018-05-25T09:23:09.710 回答