Reputation: 11794
how can I display these 3 results in 1 row? I am using the Nortwnd sample db:
select top 1 CompanyName from dbo.Customers
select top 1 LastName from employees
select top 1 categoryname from dbo.Categories
I tried Union and intersect but cant get the result.
So I would like something like:
CompanyName | LastName | CategoryName
Alfreds Futterkiste | Buchanan | Beverages
Upvotes: 0
Views: 81
Reputation: 15058
I don't understand why you would want such results, but the following would get you what you want:
SELECT TOP 1 CompanyName,
(
SELECT TOP 1 LastName FROM dbo.employees
) AS TopLastName,
(
SELECT TOP 1 categoryname FROM dbo.Categories
) AS TopCategory
FROM dbo.Customers
Upvotes: 2
Reputation: 23854
Try this:
select
CompanyName = (select top 1 CompanyName from dbo.Customers),
LastName = (select top 1 LastName from employees),
CategoryName = (select top 1 categoryname from dbo.Categories)
Upvotes: 0