I have 4 tables. These tables are the result of counting the number of entries in another table based on a category. Here's the query used to create these tables:
SELECT Category, COUNT(*) AS Number
FROM DATABASE.dbo.TABLE
GROUP BY Category;
Like I said, there are 4 of these tables created from different databases. So how could I write a query that ended up with the Category as Column1 but then the next four columns are the count results from the distinct 4 other databases?
EDIT
Incase any of that wasn't clear...
SELECT Category, COUNT(*) AS Number1
FROM DATABASE1.dbo.TABLE
GROUP BY Category;
SELECT Category, COUNT(*) AS Number2
FROM DATABASE2.dbo.TABLE
GROUP BY Category;
SELECT Category, COUNT(*) AS Number3
FROM DATABASE3.dbo.TABLE
GROUP BY Category;
SELECT Category, COUNT(*) AS Number4
FROM DATABASE4.dbo.TABLE
GROUP BY Category;
But what I want is this:
| Category | Number1 | Number2 | Number3 | Number4 |
|----------|---------|---------|---------|---------|
| | | | | |
| | | | | |
I tried
SELECT DATABASE1.dbo.TABLE.Category, DATABASE1.dbo.TABLE.COUNT(*), DATABASE2.dbo.TABLE.COUNT(*), DATABASE3.dbo.TABLE.COUNT(*), DATABASE4.dbo.TABLE.COUNT(*)
FROM DATABASE1.dbo.TABLE
JOIN DATABASE2.dbo.TABLE
ON DATABASE1.dbo.TABLE=DATABASE2.dbo.TABLE
JOIN DATABASE3.dbo.TABLE
ON DATABASE2.dbo.TABLE=DATABASE3.dbo.TABLE
JOIN DATABASE4.dbo.TABLE
ON DATABASE3.dbo.TABLE=DATABASE4.dbo.TABLE
But that didn't work.
count(*)