AlanJordan
Programmer
I have this query, which works:
I want to add the count of the number of records in another table to the query. This SQL works for that purpose:
I think the answer is to build a subquery. Can you advise me if I'm right, and the correct syntax?
This is my best shot at it, and it fails by saying that Count is not a valid object. Then SQL Server adds a CROSS JOIN in to the code.
I think I need to use a where clause and set up a correlated subquery, but I'm having difficulty with the syntax.
Thanks, in advance.
Code:
SELECT [Station Number] AS Station_Number, [Station Name] AS Station_Name, [Station City] FROM Stations
I want to add the count of the number of records in another table to the query. This SQL works for that purpose:
Code:
SELECT COUNT(ComplaintNumber) AS [No Of Complaints]
FROM dbo.Complaints2 GROUP BY [Station Number]
I think the answer is to build a subquery. Can you advise me if I'm right, and the correct syntax?
This is my best shot at it, and it fails by saying that Count is not a valid object. Then SQL Server adds a CROSS JOIN in to the code.
Code:
SELECT dbo.Stations.[Station Number], dbo.Stations.[Station Name], dbo.Stations.[Station City]
FROM dbo.Complaints2 , dbo.Count(dbo.Complaints2.ComplaintNumber) AS [Num of Complaints] LEFT OUTER JOIN
dbo.Stations ON dbo.Complaints2.[Station Number] = dbo.Stations.[Station Number]
GROUP BY Complaints.ComplaintNumber, dbo.Stations.[Station Number], dbo.Stations.[Station Name], dbo.Stations.[Station City]
I think I need to use a where clause and set up a correlated subquery, but I'm having difficulty with the syntax.
Thanks, in advance.