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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:10:23+00:00 2026-05-12T10:10:23+00:00

Ok I need to build a query based on some user input to filter

  • 0

Ok I need to build a query based on some user input to filter the results.

The query basically goes something like this:

SELECT * FROM my_table ORDER BY ordering_fld;

There are four text boxes in which users can choose to filter the data, meaning I’d have to dynamically build a “WHERE” clause into it for the first filter used and then “AND” clauses for each subsequent filter entered.

Because I’m too lazy to do this, I’ve just made every filter an “AND” clause and put a “WHERE 1” clause in the query by default.

So now I have:

SELECT * FROM my_table WHERE 1 {AND filters} ORDER BY ordering_fld;

So my question is, have I done something that will adversely affect the performance of my query or buggered anything else up in any way I should be remotely worried about?

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

    MySQL will optimize your 1 away.

    I just ran this query on my test database:

    EXPLAIN EXTENDED
    SELECT  *
    FROM    t_source
    WHERE   1 AND id < 100
    

    and it gave me the following description:

    select `test`.`t_source`.`id` AS `id`,`test`.`t_source`.`value` AS `value`,`test`.`t_source`.`val` AS `val`,`test`.`t_source`.`nid` AS `nid` from `test`.`t_source` where (`test`.`t_source`.`id` < 100)
    

    As you can see, no 1 at all.

    The documentation on WHERE clause optimization in MySQL mentions this:

    • Constant folding:

      (a<b AND b=c) AND a=5
      -> b>5 AND b=c AND a=5
      
    • Constant condition removal (needed because of constant folding):

      (B>=5 AND B=5) OR (B=6 AND 5=5) OR (B=7 AND 5=6)
      -> B=5 OR B=6
      

    Note 5 = 5 and 5 = 6 parts in the example above.

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

Sidebar

Ask A Question

Stats

  • Questions 212k
  • Answers 212k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use imagecopyresampled() instead imagecopyresized(). Check PHP's doc for usage of… May 12, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer string hexValue = "#000000"; // You do need the hash… May 12, 2026 at 10:20 pm
  • Editorial Team
    Editorial Team added an answer As a pure css solution you can use faux columns.… May 12, 2026 at 10:20 pm

Related Questions

I've got a table, called faq_questions with the following structure: id int not_null auto_increment,
I have a number of different data sources that I need to query and
I'm working now on google maps, I'm trying to build something not even half
I'm a big fan of keeping application logic in the servlet, and keeping the

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.