Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7179623
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:10:37+00:00 2026-05-28T17:10:37+00:00

So here’s my question (i’m using Oracle SQL by the way) I have 3

  • 0

So here’s my question (i’m using Oracle SQL by the way)

I have 3 result queries from my database (one is total number of hotels, one is number of hotels being constructed and one is number of hotels completed).

How do you join all three queries, so that i get 1 row, and 3 distinct columns? I’ve tried using UNION, but all that gets me is 1 column, but 3 rows.

My code looks like this:

 (SELECT COUNT(Hotel.hotelName) AS TotalHotels FROM Hotel)
 UNION
 (SELECT COUNT(Hotel.hotelName) AS NumConstructing FROM Hotel
 WHERE NOT EXISTS
 (SELECT Room.* FROM Room WHERE Room.hotelNo = Hotel.hotelNo))
 UNION
 (SELECT COUNT(Hotel.hotelName) AS NumCompleted FROM Hotel
 WHERE EXISTS
 (SELECT Room.* FROM Room WHERE Room.hotelNo = Hotel.hotelNo));

And the resulting output looks like this:

TOTALHOTELS
-----------
  2
  8
 10

I need it so that there’s only one row, and 3 columns.

Any help?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:10:39+00:00Added an answer on May 28, 2026 at 5:10 pm

    The general answer, which also works when your SELECT results have more than one column, is:

    SELECT TotalHotels, NumConstructing, NumCompleted
    FROM
        (SELECT COUNT(Hotel.hotelName) AS TotalHotels FROM Hotel)
        AS TotalHotels
    CROSS JOIN 
        (SELECT COUNT(Hotel.hotelName) AS NumConstructing FROM Hotel
         WHERE NOT EXISTS
         (SELECT Room.* FROM Room WHERE Room.hotelNo = Hotel.hotelNo))
        AS NumConstructing
    CROSS JOIN
        (SELECT COUNT(Hotel.hotelName) AS NumCompleted FROM Hotel
         WHERE EXISTS
         (SELECT Room.* FROM Room WHERE Room.hotelNo = Hotel.hotelNo))
        AS NumCompleted;
    

    although in this case, you don’t need the union/cross join:

    SELECT
        COUNT(1) AS TotalHotels,
        COUNT(CASE WHEN NOT EXISTS
         (SELECT 1 FROM Room WHERE Room.hotelNo = Hotel.hotelNo) THEN 1 END) AS NumConstructing,
        COUNT(CASE WHEN EXISTS
         (SELECT 1 FROM Room WHERE Room.hotelNo = Hotel.hotelNo) THEN 1 END) AS NumCompleted
    FROM
        Hotel;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my situation: I am using telerik with winform. I have a dataset
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here we go again, the old argument still arises... Would we better have a
Here's the basic setup: I have a thin bar at the top of a
Here is my problem : I have a post controller with the action create.
Here is the code I'm using http://jsbin.com/evike5/edit When the jQuery UI dialog is fired
Here's my problem I have this javascript if (exchRate != ) { function roundthecon()

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.