views:

44

answers:

2

I am trying to execute an SQL query on an Adaptive Server Anywhere database. Here it is:

SELECT count(*) AS s
FROM (
    SELECT column1, count(*) AS n
    FROM table1
    GROUP BY column1
    HAVING n > 1
)

In the subquery, I want to get all the rows that are duplicates and in the outer query I want a count of the rows that are duplicates.

But the database says that I have a syntax error whenever I use a subquery in the FROM clause. Is this not supported?

I am executing the query in interactive SQL in Powerbuilder. I am connected to my database using ODBC.

+3  A: 

Hi, I dont know anything about Adaptive Server, but try to add alias for the subquery in from statement, like this:

SELECT count(*) AS s
FROM (
    SELECT column1, count(*) AS n
    FROM table1
    GROUP BY column1
    HAVING n > 1
) result -- add this

MSSQL needs this to work maybe AS needs it too.

Sebastian Brózda
What do you know, it works!
YWE
A: 

ASA does not support "in memory" tables like this. You will need to create a temp table and then pull your count from there.

Erik