Home » SQL & PL/SQL » SQL & PL/SQL » How to spead up query that calls the save view multiple times (12)
How to spead up query that calls the save view multiple times [message #684428] Tue, 01 June 2021 12:10 Go to next message
helixpoint
Messages: 1
Registered: June 2021
Junior Member
I have 3 select queries that are unioned. Each sect calls the same view. Is there any way I can only call it once


select m,n,p from
cars,
THEVIEW
union
select m,n,p from
cars2,
THEVIEW
union
select m,n,p from
carss,
THEVIEW
Re: How to spead up query that calls the save view multiple times [message #684429 is a reply to message #684428] Tue, 01 June 2021 12:42 Go to previous messageGo to next message
John Watson
Messages: 8927
Registered: January 2010
Location: Global Village
Senior Member
Welcome to the forum.
Please read the OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

I don't understand what you are saying, and the SQLyou have posted is not syntactically correct. If you post the actual statement (be sure to use [code] tags to format it correctly) perhaps someone can help.
Re: How to spead up query that calls the save view multiple times [message #684430 is a reply to message #684428] Tue, 01 June 2021 12:51 Go to previous messageGo to next message
Michel Cadot
Messages: 68634
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Something like:
select m,n,p 
from THEVIEW,
     (select ... from cars
      union
      select ... from cars2
      union
      select ... from carss)
Which does not mean it'd be better (in peformances terms).

With any SQL or PL/SQL question, please, post a working Test case: create table (including all constraints) 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.
Also always post your Oracle version, with 4 decimals (query v$version), as often solution depends on it.

Re: How to spead up query that calls the save view multiple times [message #684434 is a reply to message #684430] Wed, 02 June 2021 05:55 Go to previous message
Solomon Yakobson
Messages: 3269
Registered: January 2010
Location: Connecticut, USA
Senior Member
Michel,

select m,n,p 
from THEVIEW,
     (select ... from cars
      union
      select ... from cars2
      union
      select ... from carss)
Isn't equivalent to original. Equivalent would be:

select DISTINCT m,n,p 
from THEVIEW,
     (select ... from cars
      union ALL
      select ... from cars2
      union ALL
      select ... from carss)
But you're right OP needs to post whole query.

SY.
Previous Topic: Nested Queries with Select Statement
Next Topic: View creation
Goto Forum:
  


Current Time: Tue Apr 16 01:16:21 CDT 2024