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 8423737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T03:48:22+00:00 2026-06-10T03:48:22+00:00

I hope it’s ok to make a posting like this. I have been using

  • 0

I hope it’s ok to make a posting like this.

I have been using SQL for quite some time and people at work have been using 2 different ways to return the same number or rows in a database.

For example:

SELECT Name
FROM
    Employees
WHERE
    DepartmentID IN (SELECT DepartmentID
                         FROM
                             Departments
                         WHERE
                             Department LIKE '%Engineering')

SELECT Employees.Name
FROM
    Departments
    INNER JOIN Employees
        ON Departments.DepartmentID = Employees.DepartmentID
WHERE
    Departments.Department LIKE '%Engineering'

Both return the same data. People have been telling me that using subqueries is the best way to do it.

My question is this:
Which of these 2 will execute faster? My guess would be the one with the inner join but I may be wrong.

Thanks.

  • 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-06-10T03:48:24+00:00Added an answer on June 10, 2026 at 3:48 am

    In this case, both are equivalent. However, for the one with the INNER JOIN, if there is more than 1 department selected with the same DepartmentID, employees with that DepartmentID will be returned multiple times.

    SQL is a declarative language, which means that the language is not supposed to say how the query should be performed, only what result should be found. It is up to the DMBS to work out how to perform it.

    A decent SQL database will probably optimize them to both do the same or similar things.

    To check if they are doing the same thing, run EXPLAIN on the query.

    If they have the same steps, obviously they will take the same amount of time to run. Otherwise, you will see what ways the database is treating the differently. How the DBMS optimizes it is implementation dependent. So the best way is to use EXPLAIN.

    Note: EXPLAIN is an SQL command, just like SELECT etc. See http://www.sql.org/sql-database/postgresql/manual/sql-explain.html.

    Assuming it executes with the same steps, the way you write it will be the way you think appears clearest what the intention is.

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

Sidebar

Related Questions

Hope someone could help me with this: I would like to have a column
Hope this is possible- Have a table like so: Car_ID Brand Model Year ----------------------------------
Hope somebody has a good idea. I have strings like this: abcdefg abcde abc
Hope some of you might have faced this requirement:- I have desktop based product,
hope you can help me. I have html markup like this: <a href=error.htm class=button
hope someone can answer this. Here is some sample code. namespace std { #ifdef
Hope someone will give me a hand with this problem I have. So here
Hope I'm asking this correctly: I have a project Projects.Client I have my class
Hope this makes sense, I am using Titanium mobile to build an iPhone app.
Hope you can help me with this one. I need to make a program

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.