When I run the query :
select count(*) from (select idCover from x90..dimCover group by idCover having count(*) > 1)
I get the error :
Server: Msg 170, Level 15, State 1, Line 2 Line 2: Incorrect syntax near ')'
How do I formulate this query correctly?
I'm on SQL Server 2000
A Subquery or Inner query or a Nested query is a query within another SQL query and embedded within the WHERE clause. A subquery is used to return data that will be used in the main query as a condition to further restrict the data to be retrieved.
A subquery is a query that is nested inside a SELECT , INSERT , UPDATE , or DELETE statement, or inside another subquery. The samples in this article use the AdventureWorks2016 database available for download at AdventureWorks sample databases. A subquery can be used anywhere an expression is allowed.
From clause can be used to specify a sub-query expression in SQL. The relation produced by the sub-query is then used as a new relation on which the outer query is applied. Sub queries in the from clause are supported by most of the SQL implementations.
Add an alias after your last bracket.
select count(*) from (select idCover from x90..dimCover group by idCover having count(*) > 1) a
SELECT COUNT (*) FROM ( SELECT IdCover FROM x90..dimCover group by idCover having count(*) > 1) AS a
(note the alias at the end)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With