Home » SQL & PL/SQL » SQL & PL/SQL » Combining 3 queries into 1 (Oracle11g)
Combining 3 queries into 1 [message #676357] Wed, 05 June 2019 01:31 Go to next message
ssyr
Messages: 64
Registered: January 2017
Member
Hello all,

I have 3 queries deleted, accepted, changed rows queries.
Now I have to combine all 3 queries into 1 .I am able to combine 2 queries (deleted and accepted) but when tried to combine changed query with other2 I am getting error.

Can anyone suggest me how can I combine these 3 queries.

Please see the attached file for all queries.
  • Attachment: Query.sql
    (Size: 4.38KB, Downloaded 286 times)
Re: Combining 3 queries into 1 [message #676358 is a reply to message #676357] Wed, 05 June 2019 01:48 Go to previous messageGo to next message
John Watson
Messages: 8052
Registered: January 2010
Location: Global Village
Senior Member
If you want to "combine" queries, use a set operator. It is what they are for. For example,
orclx> with d10 as (select * from emp where deptno=10),
  2  d20 as (Select * from emp where deptno=20)
  3  select * from d10
  4  union all
  5  select * from d20;

     EMPNO ENAME      JOB              MGR HIREDATE                   SAL       COMM     DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
      7782 CLARK      MANAGER         7839 1981-06-09:00:00:00       2450                    10
      7839 KING       PRESIDENT            1981-11-17:00:00:00       5000                    10
      7934 MILLER     CLERK           7782 1982-01-23:00:00:00       1300                    10
      7369 SMITH      CLERK           7902 1980-12-17:00:00:00        800                    20
      7566 JONES      MANAGER         7839 1981-04-02:00:00:00       2975                    20
      7788 SCOTT      ANALYST         7566 1987-04-19:00:00:00       3000                    20
      7876 ADAMS      CLERK           7788 1987-05-23:00:00:00       1100                    20
      7902 FORD       ANALYST         7566 1981-12-03:00:00:00       3000                    20

8 rows selected.

orclx>
Re: Combining 3 queries into 1 [message #676359 is a reply to message #676358] Wed, 05 June 2019 01:59 Go to previous messageGo to next message
ssyr
Messages: 64
Registered: January 2017
Member
Thank you for looking into my query.

But my problem is I have common query part that comes in WITH clause. I have used that common part in WITH and using same data for 3 queries.It is working fine for 2 queries -Deleted and Accepted.
But not working for 'Changed ' query.

in changed query I have to add two queries and retrieve the result. That I am not able to do.
Re: Combining 3 queries into 1 [message #676360 is a reply to message #676359] Wed, 05 June 2019 02:26 Go to previous messageGo to next message
John Watson
Messages: 8052
Registered: January 2010
Location: Global Village
Senior Member
So what is wrong with my solution?
And what does "But not working for 'Changed ' query" mean?
Re: Combining 3 queries into 1 [message #676362 is a reply to message #676360] Wed, 05 June 2019 03:15 Go to previous messageGo to next message
cookiemonster
Messages: 13721
Registered: September 2008
Location: Rainy Manchester
Senior Member
You need to post the queries directly in the thread (in [code] tags). A lot of people won't / can't download attachments.

You also need to tell us exactly what error you're getting.
Re: Combining 3 queries into 1 [message #676378 is a reply to message #676362] Wed, 05 June 2019 11:15 Go to previous message
Bill B
Messages: 1909
Registered: December 2004
Senior Member
agreed, I will NOT download or open your query.sql
Take the contents of the file and past it into the thread
Previous Topic: Approximate 50MB files per day to be saved in Oracle Database
Next Topic: PLS-00306: wrong number or types of arguments in call to 'FOPEN' (CM merged 2)
Goto Forum:
  


Current Time: Mon Nov 18 15:00:47 CST 2019