我有以下存储过程返回大量行。我想将行数限制为50.如何在SQL Server数据库的UNION SELECT
查询中执行此操作?
CREATE PROCEDURE [dbo].[SD_photos]
(@IDuser NVARCHAR(50))
AS
BEGIN
SET NOCOUNT ON;
SELECT
photoFileName
FROM
photos
WHERE
IDuser = @IDuser
UNION ALL
SELECT
photoFileName
FROM
photos2
WHERE
IDuser = @IDuser
END
答案 0 :(得分:1)
这似乎是MS SQL Server,因此您可以使用TOP语法:
SELECT TOP 50 *
FROM
(
SELECT photoFileName FROM photos WHERE IDuser = @IDuser
UNION ALL
SELECT photoFileName FROM photos2 WHERE IDuser = @IDuser
) dt