Home » SQL & PL/SQL » SQL & PL/SQL » union (sql)
union [message #641158] Tue, 11 August 2015 05:56 Go to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Can anyone please help me to solve this error, actually i would like to make Union all to create one view from these two query, but i am getting error ora_01789 and i am also known why i am getting this error but i don't know how could i solve it.
help please?

select rid, r_pr, r_ml
  from rm
  where exists ( select 1 from rjs
                           where rjs.rid = rm.rid and rjs.text in ('TPD'))
UNION ALL
select rid
  from rjs
  where not in (select rm.rid from rm, rjf
                               where rjf.rid = rm.rid
                               and rjf.r_pr = rm.r_pr)
 and rjs.text in ('TPD');

Should it be have same field in both table while making Union? In my case there is no same fields in the table, but some of rid are not in the first table, thats why i would like to get These rid in the first table too.

thank u
Re: union [message #641160 is a reply to message #641158] Tue, 11 August 2015 06:20 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

You must have the same number and type of fields in both queries you union.

Re: union [message #641162 is a reply to message #641160] Tue, 11 August 2015 06:24 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
If there is no equivalent in the second query then null will do.
Re: union [message #641163 is a reply to message #641160] Tue, 11 August 2015 06:35 Go to previous messageGo to next message
palpali
Messages: 138
Registered: December 2014
Location: India
Senior Member
Thank you Michel. Ya, I also checked it Smile

well, then can i do this my query as:

select rid, r_pr, r_ml
  from rm
  where exists ( select 1 from rjs
                           where rjs.rid = rm.rid and rjs.text in ('TPD'))
UNION ALL
select * from rm
where (
       select rid
       from rjs
       where not in (select rm.rid from rm, rjf
                               where rjf.rid = rm.rid
                               and rjf.r_pr = rm.r_pr)
       and rjs.text in ('TPD'));


I changed it so.. n got error ORA-00936.
any Suggestion please?

Re: union [message #641164 is a reply to message #641163] Tue, 11 August 2015 06:41 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
Since when is
WHERE (<subquery>)

valid syntax?
Re: union [message #641167 is a reply to message #641164] Tue, 11 August 2015 07:06 Go to previous message
pablolee
Messages: 2882
Registered: May 2007
Location: Scotland
Senior Member
cookiemonster wrote on Tue, 11 August 2015 12:41
Since when is
WHERE (<subquery>)

valid syntax?


Same version as
where not in (subquery)
? Razz
Previous Topic: Oracle analytic query help
Next Topic: Transpose of rows to Columns & Dynamically Adding the Columns (merged)
Goto Forum:
  


Current Time: Fri Apr 26 05:51:15 CDT 2024