Consider my DB2 query as below.
Select something from some tables,
(select something from some tables where bhla=bhla
Unionall
select something from some tables where bhla=bhla
union
select something from some tables where bhla=bhla) x
where bhla=bhla
and it looks like
select x.something, y.somethingelse from table y,
(select something from some tables where bhla=bhla
Unionall
select something from some tables where bhla=bhla
union
select something from some tables where bhla=bhla) x
where bhla=bhla
My query is to optimise the above query(better way of use the query). please provide some inputs on indexes and how to use it. I need to optimise the above query so please pour some suggesstion.
Can you guyz suggest hw to recode the below where clause
where
(ID.EXCH_RT <> 0.000000 AND ID.EXCH_RT IS NOT NULL)
AND I.ACT_LOC_TS BETWEEN ( :Param_290_From_Date CONCAT ' 00:00:00.00000') AND ( :Param_300_To_Date CONCAT ' 23:59:59.99999')
It is not possible to optimize with the information given.
Normally people are just referred to How to Ask a Question when they ask a question that isn't specific enough. However, I see a lot of this specific case: asking for help with optimizing an SQL query that is not well-defined. So I wanted to address what is wrong here in more detail.
Why can't this be optimized?
We don't know the task. Optimization is something you do for a task, not a piece of code. Your goal is to get the task done as efficiently as possible. The code you have posted may or may not be the best way of doing that. If we only have the code, and don't know what the code is for, we have no way of assessing the appropriateness of your code.
We don't know the table structure. Optimization for SQL very much depends on the structure of the tables in question. What columns are involved, and what datatypes? How do the tables relate to each other? In this case, we don't even know how many tables are involved, because some of the queries act on "some tables".
We don't know the data. How big is each table? Consider the example query below. Is it optimized? The answer is, that all depends on the data. If
table1
is small andtable2
is huge, that would be a good way to optimize the query. However, iftable1
is huge andtable2
is small, that would be a very poor query design that wastes lots of time. There is no way to tell the best design without knowing anything about the data.It depends on what database you are using (Thanks WarrenT). In this case, you have specified DB2, which is a good start compared to the many questions that just state "SQL". However, it would still be helpful to know which platform and version you are using. This makes a significant difference in what features are available.
Example query:
I hope this is helpful. We would be glad to help further if you provide more information.