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

  • Home
  • SEARCH
  • 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 8930153
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:49:16+00:00 2026-06-15T08:49:16+00:00

I have two sql queries as following SELECT rc.stateId,rs.stateName FROM (SELECT DISTINCT cityid FROM

  • 0

I have two sql queries as following

SELECT rc.stateId,rs.stateName FROM
(SELECT DISTINCT cityid FROM HolidayPackageCity) AS hpc
 INNER JOIN 
 (SELECT cityid,stateid FROM RegCity WHERE countryCode='IN' AND stateId IS NOT NULL) AS rc
ON hpc.cityId=rc.cityId
INNER JOIN
RegState AS rs
ON rc.stateId=rs.stateId

vs

SELECT DISTINCT rc.stateId,rs.stateName 
FROM HolidayPackageCity AS hpc
INNER JOIN 
  RegCity  AS rc
  ON hpc.cityId=rc.cityId
  INNER JOIN
    RegState AS rs
    ON rc.stateId=rs.stateId
WHERE rc.countryCode='IN' AND rc.stateId IS NOT NULL

In first query first i filter the data of a particular table then apply joining and in second table first i apply joins then i apply where condition to filter the data.
The thing i want to know is which one is faster from both of that and why.

  • 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-15T08:49:19+00:00Added an answer on June 15, 2026 at 8:49 am

    Second query is faster, because optimizer would first filter table with where clause, and then create internal temp table which later use for join. Conclusion – better solution is join with tables which contains smaller data sets.

    By the way, optimizer easier deal with second query, which no contains subqueries.

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

Sidebar

Related Questions

I have two queries, as following: SELECT SQL_CALC_FOUND_ROWS Id, Name FROM my_table WHERE Name
I have two sql queries: $query0=mysql_query(SELECT caseNumber FROM shipped_data WHERE palette='P0' AND shipInvoiceNumber='2011/229'); $query1=mysql_query(SELECT
I have a small sql question for you. I have two queries: SELECT tbl_CostPrevisions.Month,
I have two SQL queries: A. SELECT (upper(rtrim(ltrim(lastname))) + upper(rtrim(ltrim(firstname))) + upper(rtrim(ltrim(middlename))) + rtrim(ltrim(v))
I have two SQL queries, where the first one is: select Activity, SUM(Amount) as
I have the following two SQL statements First one: IF(@User_Id IS NULL) BEGIN SELECT
I currently have two SQL commands. One retrieves a list of unique IDs from
I have two SQL queries producing different results when I would expect them to
I have this 2 following SQL Queries on my grails controller: def query1 =
We have the following code: select * from View1 where (Timestamp >= @x) and

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.