Is there any way to do selects from a single Select in Microsoft SQL Server?
Something like :
SELECT id, type, name, address
FROM Persons AS Persons_DATA
WHERE (name='...' OR name in ('...','...'))
SELECT TOP 1 'Best Vendor : '+name from Persons_DATA where type=1 order by ...
union SELECT TOP 1 'Best Customer : '+name from Persons_DATA where type=2 order by ...
union SELECT TOP 1 'Least Debt : '+name from Persons_DATA where ... order by ...
union SELECT TOP 1 'Most Debt : '+name from Persons_DATA where ... order by ...
...
I know I can do :
SELECT TOP 1
'Best Vendor : '+name
FROM
Persons
WHERE
type = 1 AND (name='...' OR name in ('...','...'))
ORDER BY ...
UNION
SELECT TOP 1
'Best Customer : '+name
FROM
Persons
WHERE
type = 2
AND (name='...' OR name in ('...','...'))
ORDER BY ...
But I think this will take more time because it will do many unnecessary searches in a big data base
but the first code will only do 1 search in the big database and X searches in a small database and it will take less time.... am I right?
TOPwithout anORDER BY? I don't understand what are you trying to do there.