Home » SQL & PL/SQL » SQL & PL/SQL » Multiple Queries into different columns (SQL Developer)
Multiple Queries into different columns [message #576133] Thu, 31 January 2013 22:59 Go to next message
nibugeorge
Messages: 5
Registered: January 2013
Location: USA
Junior Member
I am trying to validate a monthly report so was trying to write queries to get different criteria into one table.
So my first query returns all the product,second query returns all the enrolled customers, 3rd query returns all the cancelled customers and 4th query returns all the newly enrolled for a month. Is there a way I can pass the first query results into 1st column, 2 query results into 2nd column, 3 query results into 3rd column and so on.

I tired writing the SQL several different ways and have spent a day on it and still cannot figure it out. If anybody could help with this it will be highly appreciated. I am using SQL Developer.

Thanks.
Re: Multiple Queries into different columns [message #576135 is a reply to message #576133] Thu, 31 January 2013 23:20 Go to previous messageGo to next message
BlackSwan
Messages: 21938
Registered: January 2009
Senior Member
Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/

Stop whining!
Realize that we don't have your tables, your data, & your requirements.
So why do you expect we can write SQL for you?
Re: Multiple Queries into different columns [message #576136 is a reply to message #576135] Thu, 31 January 2013 23:26 Go to previous messageGo to next message
nibugeorge
Messages: 5
Registered: January 2013
Location: USA
Junior Member
Here is an example of what I am trying to do:

SELECT
(select count(*) as enrolled
from GC.T_PROFILE_ENROLLMENT
where status in('E')) AS Column1,
(select count(*) as Cancelled
from GC.T_PROFILE_ENROLLMENT
where status in ('C') ) AS Column2
(select count(*) as NewlyEnrolled
from GC.T_PROFILE_ENROLLMENT
where status in ('E')
and date > '01-01-2013') AS Column3
Re: Multiple Queries into different columns [message #576137 is a reply to message #576136] Thu, 31 January 2013 23:34 Go to previous messageGo to next message
BlackSwan
Messages: 21938
Registered: January 2009
Senior Member
Interesting, but I don't believe posted code is valid & executable SQL.

using COPY & PASTE show what results from posted code.

>'01-01-2013' is NOT a date; but a string just like 'I can not spell'!
Re: Multiple Queries into different columns [message #576138 is a reply to message #576137] Thu, 31 January 2013 23:37 Go to previous messageGo to next message
nibugeorge
Messages: 5
Registered: January 2013
Location: USA
Junior Member
I dont think its the issue with the date:
SELECT
(select count(*) as enrolled
from GC.T_PROFILE_ENROLLMENT
where status in('E')) AS Column1,
(select count(*) as Cancelled
from GC.T_PROFILE_ENROLLMENT
where status in ('C') ) AS Column2
(select count(*) as NewlyEnrolled
from GC.T_PROFILE_ENROLLMENT
where status in ('E')
and date > '01-JAN-2013') AS Column3

You get what I am trying to do, so stop trying to be some kind of a bully. if you a dont have an answer get a life and move on!!
Re: Multiple Queries into different columns [message #576139 is a reply to message #576138] Thu, 31 January 2013 23:39 Go to previous messageGo to next message
BlackSwan
Messages: 21938
Registered: January 2009
Senior Member
Interesting, but I don't believe posted code is valid & executable SQL.

using COPY & PASTE show what results from posted code.
Re: Multiple Queries into different columns [message #576140 is a reply to message #576139] Thu, 31 January 2013 23:45 Go to previous messageGo to next message
nibugeorge
Messages: 5
Registered: January 2013
Location: USA
Junior Member
I have no idea what you are trying to say. Are you trying to say I copy pasted this code? If so you are wrong. I wrote this and have been trying to get it work so not sure what you are hinting at?
Re: Multiple Queries into different columns [message #576141 is a reply to message #576140] Thu, 31 January 2013 23:54 Go to previous messageGo to next message
rishwinger
Messages: 132
Registered: November 2011
Senior Member
SQL> select (select count(*) from dept ) as col1 , (select count(*) from emp) as
 col2 from dual;

      COL1       COL2
---------- ----------
         4         14


use "from dual" in the end of the sql query
Re: Multiple Queries into different columns [message #576149 is a reply to message #576141] Fri, 01 February 2013 00:44 Go to previous messageGo to next message
nibugeorge
Messages: 5
Registered: January 2013
Location: USA
Junior Member
Thanks. I will try adding that "from dual". Appreciate your help.
Re: Multiple Queries into different columns [message #576154 is a reply to message #576149] Fri, 01 February 2013 00:57 Go to previous message
Michel Cadot
Messages: 57606
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.
Make sure that lines of code do not exceed 80 characters when you format.
Indent the code, use code tags and align the columns in result.
Use the "Preview Message" or "Preview Quick Reply" button to verify.
Also always post your Oracle version, with 4 decimals.

With any SQL or PL/SQL question, please, Post a working Test case: create table and insert statements along with the result you want with these data then we will be able work with your table and data. Explain with words and sentences the rules that lead to this result.

Do NOT use SELECT in SELECT clause until you'll be an expert in SQL and know what you do.

Regards
Michel
Previous Topic: Conditional Sequence usage
Next Topic: Insert 999999 records in table
Goto Forum:
  


Current Time: Thu Apr 17 09:14:22 CDT 2014

Total time taken to generate the page: 0.07568 seconds