Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6588883
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T17:06:14+00:00 2026-05-25T17:06:14+00:00

When we create a join between 2 tables in Oracle, with some additional filter

  • 0

When we create a join between 2 tables in Oracle, with some additional filter condition on one or both tables, will oracle join the tables first and then filter or will it filter the conditions first and then join.

Or in simple words, which of these 2 is a better query

Say we have 2 tables Employee and Department, and I want employees all employee + dept detail where employee salary is grater than 50000

Query 1:
select e.name, d.name from employee e, department d where e.dept_id=d.id and e.salary>50000;

Query 2:
select e.name, d.name from (select * from employee where salary>50000) e, department d where e.dept_id=d.id;

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T17:06:14+00:00Added an answer on May 25, 2026 at 5:06 pm

    Generally it will filter as much as possible first. From the explain plan, you can actually see where the filtering is done, and where the joining is done, for example, create some tables and data:

    create table employees (id integer, dept_id integer, salary number);
    
    create table dept (id integer, dept_name varchar2(10));
    
    insert into dept values (1, 'IT');
    
    insert into dept values (2, 'HR');
    
    insert into employees
    select level, mod(level, 2) + 1, level * 1000
    from dual connect by level <= 100;
    
    create index employee_uk1 on employees (id);
    
    create index dept_uk1 on dept (id);
    
    exec dbms_stats.gather_table_stats(user, 'DEPT');
    

    Now if I explain both the queries you provided, you will find that Oracle transforms each query into the same plan behind the scenes (it doesn’t always execute what you think it does – Oracle has license to ‘rewrite’ the query, and it does it a lot):

    explain plan for
    select e.*, d.*
    from employees e, dept d
    where e.dept_id = d.id
    and e.salary > 5000;
    
    select * from table(dbms_xplan.display());
    
        ------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |           |    96 |  1536 |     6  (17)| 00:00:01 |
    |   1 |  MERGE JOIN                  |           |    96 |  1536 |     6  (17)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT      |     2 |    12 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FULL SCAN           | DEPT_UK1  |     2 |       |     1   (0)| 00:00:01 |
    |*  4 |   SORT JOIN                  |           |    96 |   960 |     4  (25)| 00:00:01 |
    |*  5 |    TABLE ACCESS FULL         | EMPLOYEES |    96 |   960 |     3   (0)| 00:00:01 |
    
    4 - access("E"."DEPT_ID"="D"."ID")
        filter("E"."DEPT_ID"="D"."ID")
    5 - filter("E"."SALARY">5000)
    

    Notice the filter operations applied to the query. Now explain the alternative query:

    explain plan for
    select e.*, d.*
    from (select * from employees where salary > 5000) e, dept d
    where e.dept_id = d.id;
    
    ------------------------------------------------------------------------------------------
    | Id  | Operation                    | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    ------------------------------------------------------------------------------------------
    |   0 | SELECT STATEMENT             |           |    96 |  1536 |     6  (17)| 00:00:01 |
    |   1 |  MERGE JOIN                  |           |    96 |  1536 |     6  (17)| 00:00:01 |
    |   2 |   TABLE ACCESS BY INDEX ROWID| DEPT      |     2 |    12 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FULL SCAN           | DEPT_UK1  |     2 |       |     1   (0)| 00:00:01 |
    |*  4 |   SORT JOIN                  |           |    96 |   960 |     4  (25)| 00:00:01 |
    |*  5 |    TABLE ACCESS FULL         | EMPLOYEES |    96 |   960 |     3   (0)| 00:00:01 |    
    
    4 - access("EMPLOYEES"."DEPT_ID"="D"."ID")
        filter("EMPLOYEES"."DEPT_ID"="D"."ID")
    5 - filter("SALARY">5000)
    

    Once you learn how to get the explain plans and how to read them, you can generally work out what Oracle is doing as it executes your query.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i want to create a join between two tables and that the result will
Using Django's built in models, how would one create a triple-join between three models.
i have the following linq query that create a left join between two tables:
I'm trying to create a relation that has a between join. Here is a
I have two tables that I'm trying to create a relationship between so I
I'm trying to force Linq to preform an inner join between two tables. I'll
I'm implementing a view on a model with three tables, one of them join
I am trying to join two tables. One being the sys.databases table and the
I have a complicated join between a few tables but I have managed to
I have to create a temp tables...But the problem is if multiple user will

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.