I currently have the following code in a stored procedure (see below). In an effort to return 10 results total, I take the TOP 5 of each union-half. However, I’d like to take the TOP 10 of the UNION, and not necessarily 5 of each. Any ideas? Is this possible?
BEGIN
SELECT TOP 5
a_object_ID as [id],
a_object_name as [name],
'A_object' as [Type]
FROM [database].[dbo].[table_a]
WHERE a_object_name LIKE @Search + '%'
UNION ALL
SELECT TOP 5
b_object_ID as [id],
b_object_name as [name],
'B_object' as [Type]
FROM [database].[dbo].[table_b]
WHERE b_object_name LIKE @Search + '%'
ORDER BY [name]
END
How about this?