Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 802
  • Last Modified:

SQL cross join syntax problem

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
simplyfemales
Asked:
simplyfemales
2 Solutions
 
Brian ChanDBACommented:
instead, try this

select count(*) 'VolumeA' from tableA
cross join
(select count(*) 'VolumeB' from tableB)
0
 
Brian ChanDBACommented:
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
 
simplyfemalesAuthor Commented:
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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 
Brian ChanDBACommented:
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
 
Pratima PharandeCommented:
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
 
Kevin CrossChief Technology OfficerCommented:
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
 
Brian ChanDBACommented:
@simplyfemales, seriously if you are not obsessive with using cross join, mwvisa1's solution is much cleaner cut.
0
 
simplyfemalesAuthor Commented:
Both great suggestions.  Thanks.
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now