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

The Archive Base Latest Questions

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

I want to be able to fetch results from mysql with a statement like

  • 0

I want to be able to fetch results from mysql with a statement like this:

SELECT * 
  FROM table 
 WHERE amount > 1000 

But I want to fetch the result constrained to a certain a month and year (based on input from user)… I was trying like this:

SELECT * 
  FROM table 
 WHERE amount > 1000 
   AND dateStart = MONTH('$m')   

…$m being a month but it gave error.

In that table, it actually have two dates: startDate and endDate but I am focusing on startDate. The input values would be month and year. How do I phrase the SQL statement that gets the results based on that month of that year?

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

    You were close – got the comparison backwards (assuming startDate is a DATETIME or TIMESTAMP data type):

    SELECT * 
      FROM table 
     WHERE amount > 1000 
       AND MONTH(dateStart) = {$m}
    

    Caveats:


    • Mind that you are using mysql_escape_string or you risk SQL injection attacks.
    • Function calls on columns means that an index, if one exists, can not be used

    Alternatives:


    Because using functions on columns can’t use indexes, a better approach would be to use BETWEEN and the STR_TO_DATE functions:

    WHERE startdate BETWEEN STR_TO_DATE([start_date], [format]) 
                        AND STR_TO_DATE([end_date], [format])
    

    See the documentation for formatting syntax.

    Reference:


    • MONTH
    • YEAR
    • BETWEEN
    • STR_TO_DATE
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to fetch the XML result from an exmaple query like this: http://maps.googleapis.com/maps/api/directions/xml?origin=Toronto,ON&destination=Manhattan,NY&dirflg=r&sensor=false
I want to be able to separate the birthday from the mysql data into
I want to be able to fetch a row from a list view and
I want to be able to use a wildcard in string::find and then fetch
I asked a similar question like this yesterday but after waiting for ever I
I have the following query: $result = mysql_query("SELECT option_value FROM wp_10_options WHERE option_name='homepage'"); $row
I am trying to fetch results from my sqlite database by providing a date
I want to show a random record from the database. I would like to
Can someone suggest me a good example or link to select records from MySQL
This is the sort of thing I want to be able to do. I

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.