edited by
1,438 views
2 votes
2 votes

A single query in DBMS can be executed through different algorithms or re-written in different forms and structures. The most optimal pathway of getting the correct output among all these algorithms can be obtained by the process of query optimization.
Consider the following query:
With emp_table as select columnA from Employee where columnB> 3000;
Emp_table intersect (select columnA from Emp_table where columnC<3000);
Identify the correct optimized SQL query.

  1. select columnA from Employee where columnB>3000 intersect select columnA from Employee where columnC<3000;
  2. select columnA from Employee where columnB >3000 and columnC<3000;
  3. select columnA from Employee;
  4. The given query is already in optimized form.
edited by

1 Answer

Best answer
1 votes
1 votes

(B) is the correct option! 

As, SQL is a row by row processing of the relation data, it takes one row apply both the conditions

where $columnB>3000$ and $ColumnC<3000$,

And, if the record passes both the conditions then it will be selected. if there are n records in a table then we need to fetch exactly them once.

But if we first find those records where $columnB>3000$ and then we find the records where $ColumnC<3000$, and then take their INTERSECTION, then it's a too much work, as, first we are fetching the entire table twice and then applying INTERSECTION operation, furthermore, intersection is an expensive operation because it has to compare the results set and then it removes duplicate also.

selected by
Answer:

Related questions

1 votes
1 votes
1 answer
4