UNION clause syntax question 
Author Message
 UNION clause syntax question
Is there any way I can rewrite this query so it will return only the record count?

SELECT visitorid
FROM VISITOR
UNION ALL
SELECT visitorid
FROM ArchiveVISITOR
UNION ALL
SELECT visitorid
FROM DELETEDVISITOR

Thanks,
tg



Tue, 07 Sep 2004 23:29:23 GMT
 UNION clause syntax question

TG,

  You can do it this way

select count(*) from (
SELECT visitorid
FROM VISITOR
UNION ALL
SELECT visitorid
FROM ArchiveVISITOR
UNION ALL
SELECT visitorid
FROM DELETEDVISITOR
) X

Steve Kass
Drew University

Quote:

> Is there any way I can rewrite this query so it will return only the record count?

> SELECT visitorid
> FROM VISITOR
> UNION ALL
> SELECT visitorid
> FROM ArchiveVISITOR
> UNION ALL
> SELECT visitorid
> FROM DELETEDVISITOR

> Thanks,
> tg



Tue, 07 Sep 2004 23:36:07 GMT
 UNION clause syntax question
Did you try
select count(*) from (
 SELECT visitorid
 FROM VISITOR
 UNION ALL
 SELECT visitorid
 FROM ArchiveVISITOR
 UNION ALL
 SELECT visitorid
 FROM DELETEDVISITOR
)


Quote:
> Is there any way I can rewrite this query so it will return only the
record count?

> SELECT visitorid
> FROM VISITOR
> UNION ALL
> SELECT visitorid
> FROM ArchiveVISITOR
> UNION ALL
> SELECT visitorid
> FROM DELETEDVISITOR

> Thanks,
> tg



Tue, 07 Sep 2004 23:35:59 GMT
 UNION clause syntax question
Steve -

Thanks.  That works.  One question, though:  What does the 'X' mean at
the end of the statement?

tg

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!



Wed, 08 Sep 2004 00:27:41 GMT
 UNION clause syntax question
Tom,

  When using a derived table, which is what the
select statement in parentheses is called, there is a
requirement that it be aliased with some identifier.
Even though the X isn't used, it has to be there according
to the SQL syntax rules.

Steve

Quote:

> Steve -

> Thanks.  That works.  One question, though:  What does the 'X' mean at
> the end of the statement?

> tg

> *** Sent via Developersdex http://www.developersdex.com ***
> Don't just participate in USENET...get rewarded for it!



Wed, 08 Sep 2004 01:02:48 GMT
 
 [ 5 post ] 

 Relevant Pages 

1. UNION Clause Question

2. UNION clause questions

3. SQL question: using UNION in FROM clause with DB2 V5

4. UNION Clause unsupporter?

5. Order By clause with UNION : SQL Server 2000

6. Using UNION and ORDER BY clauses

7. INTO Clause with UNION?

8. union in where clause causing problems?

9. Stored Procedure - TOP/UNION clauses

10. Union Clause help needed

11. Union Clause

12. Parameterised queries and UNION clause


 
Powered by phpBB® Forum Software