Solved

SQL cross join syntax problem

Posted on 2011-09-12
8
685 Views
Last Modified: 2012-05-12
select count(*) 'VolumeA' from tableA
cross join
select count(*) 'VolumeB' from tableB

error says "Incorrect syntax near the keyword 'select'"

I simply like the counts to be side by side.

Suggestions?
0
Comment
Question by:simplyfemales
8 Comments
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527158
instead, try this

select count(*) 'VolumeA' from tableA
cross join
(select count(*) 'VolumeB' from tableB)
0
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527172
Ooooo.... What am I doing?

It should be:

Select tabA.VolumeA, tabB.VolumeB
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB
0
 

Author Comment

by:simplyfemales
ID: 36527220
Select tabA.VolumeA, tabB.VolumeB
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB

doesn't work.

Incorrect syntax near the keyword 'select'
Incorrect syntax near ')'
Incorrect syntax near the keyword 'as'
0
 
LVL 5

Accepted Solution

by:
Brian Chan earned 125 total points
ID: 36527239
My typo..... I missed the FROM

Select tabA.VolumeA, tabB.VolumeB
FROM
(select count(*) 'VolumeA' from tableA) as tabA
cross join
(select count(*) 'VolumeB' from tableB) as tabB
0
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
LVL 39

Expert Comment

by:Pratima Pharande
ID: 36527242
cross join works like this

chabge ID_A and ID_B as per your column names

select count(ID_A) 'VolumeA' , Count(ID_B) 'VolumeB'  from tableA
cross join tableB
0
 
LVL 59

Assisted Solution

by:Kevin Cross
Kevin Cross earned 125 total points
ID: 36527262
An you probably just want something simple like this:

SELECT (SELECT COUNT(1) FROM tableA) AS VolumeA
      , (SELECT COUNT(1) FROM tableB) AS VolumeB
;

Open in new window

0
 
LVL 5

Expert Comment

by:Brian Chan
ID: 36527423
@simplyfemales, seriously if you are not obsessive with using cross join, mwvisa1's solution is much cleaner cut.
0
 

Author Closing Comment

by:simplyfemales
ID: 36530176
Both great suggestions.  Thanks.
0

Featured Post

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

I have written a PowerShell script to "walk" the security structure of each SQL instance to find:         Each Login (Windows or SQL)             * Its Server Roles             * Every database to which the login is mapped             * The associated "Database User" for this …
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now