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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T10:05:11+00:00 2026-06-10T10:05:11+00:00

Suppose I have a student table contains id , class , school_id having 1000

  • 0

Suppose I have a student table contains id, class, school_id having 1000 records.

There are 3 schools and 12 classes.

Which of these 2 queries would be faster(if there is a difference)

Query 1:

SELECT * FROM student WHERE school = 2 and class = 5; 

Query 2:

SELECT * FROM student WHERE class = 5 and school = 2;

Note: I just changed the places of the 2 conditions in WHERE.

Then which will be faster and Is the following true?

->probable number of records in query1 is 333

->probable number of records in query2 is 80.

  • 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-10T10:05:12+00:00Added an answer on June 10, 2026 at 10:05 am

    hypothetical; to teach a DB concept

    "How your DB uses cardinality to optiize your queries"

    So, it’s basically true that they are identical, but I will mention one thought hinting at the "why" which will actually introduce a good RDBMS concept.

    Let’s just say hypothetically that your RDBMS used the WHERE clauses strictly in the order you specified them.

    In that case, the optimal query would be the one in which the column with maximum cardinality was specified first. What that means is that specifying class=5 first would be faster, as it more quickly eliminates rows from consideration, meaning if the row’s "class" column does not contain 5 (which is statistically more likely than it’s "school" column not containing 2), then it doesn’t even need to evaluate the "school" column.

    Coming back to reality, however, you should know that almost all modern relational database management systems do what is called "building a query plan" and "compiling the query". This involves, among other things, evaluating the cardinality of columns specified in the WHERE clause (and what indexes are available, etc). So essentially, it is probably true to say they are identical, and the number of results will be, too.

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

Sidebar

Related Questions

Suppose that I have the following HBM mapping: <class name=Student table=student> <set name=classes table=student_classes
Suppose I have two classes: public class Student { public int Id {get; set;}
Suppose I have table as below: Class Student Maths English ------------------------------------ 1 a 50
Suppose I have a class Baz that inherits from classes Foo and Bar ,
Suppose: I have a single table that holds the book ID, student ID and
Suppose I have three models: Student , SchoolClass , and DayOfWeek . There is
A simple question on how database Indexes work. Suppose i have a table 'Student'
Suppose I have the following student table: id | name | datecreated ------------------------ 1
Suppose you have a table widget class. Do you do table.row(i).column(0).setText(students[i].surname()) or table[0][i] =
Suppose i have a base class person. and i publically inherits a class student

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.