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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T00:05:04+00:00 2026-06-12T00:05:04+00:00

Im running a sql query that is returning results between dates I have selected

  • 0

Im running a sql query that is returning results between dates I have selected (2012-07-01 – 2012-08-01). I can tell from the values they are wrong though.

Im confused cause its not telling me I have a syntax error but the values returned are wrong.

The dates in my database are stored in the date column in the format YYYY-mm-dd.

SELECT `jockeys`.`JockeyInitials` AS `Initials`, `jockeys`.`JockeySurName` AS Lastname`,
       COUNT(`runs`.`JockeysID`) AS 'Rides', 
       COUNT(CASE
                  WHEN `runs`.`Finish` = 1 THEN 1 
                  ELSE NULL 
             END
             ) AS  `Wins`, 
        SUM(`runs`.`StakeWon`) AS 'Winnings'
  FROM runs
 INNER JOIN jockeys ON runs.JockeysID = jockeys.JockeysID
 INNER JOIN races ON runs.RacesID = races.RacesID
 WHERE `races`.`RaceDate` >= STR_TO_DATE('2012,07,01', '%Y,%m,%d')
   AND `races`.`RaceDate` <= STR_TO_DATE('2012,08,01', '%Y,%m,%d')
 GROUP BY `jockeys`.`JockeySurName` 
 ORDER BY `Wins` DESC`
  • 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-12T00:05:05+00:00Added an answer on June 12, 2026 at 12:05 am

    It’s hard to guess what the problem is from your question.

    Are you looking to summarize all the races in July and the races on the first of August? That’s a slightly strange date range.

    You should try the following kind of date-range selection if you want to be more precise. You MUST use it if your races.RaceDate column is a DATETIME expression.

     WHERE `races`.`RaceDate` >= STR_TO_DATE('2012,07,01', '%Y,%m,%d')
       AND `races`.`RaceDate` <  STR_TO_DATE('2012,08,01', '%Y,%m,%d') + INTERVAL 1 DAY
    

    This will pick up the July races and the races at any time on the first of August.

    But, it’s possible you’re looking for just the July races. In that case you might try:

     WHERE `races`.`RaceDate` >= STR_TO_DATE('2012,07,01', '%Y,%m,%d')
       AND `races`.`RaceDate` <  STR_TO_DATE('2012,07,01', '%Y,%m,%d') + INTERVAL 1 MONTH
    

    That will pick up everything from midnight July 1, inclusive, to midnight August 1 exclusive.

    Also, you’re not using GROUP BY correctly. When you summarize, every column in your result set must either be a summary (SUM() or COUNT() or some other aggregate function) or mentioned in your GROUP BY clause. Some DBMSs enforce this. MySQL just rolls with it and gives strange results. Try this expression.

    GROUP BY `jockeys`.`JockeyInitials`,`jockeys`.`JockeySurName` 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a custom SQL call that is returning different results to the template
I have a long-running SQL Server 2005 query that I have been hoping to
I have a simple SQL query that when run from C# takes over 30
I am running a SQL query that returns a table of results. I want
I have a query that seems to be returning the wrong data from the
I have an SQL Query that i'm running but I only want to select
I have a SQL query that is quite simply select * from tblOrders where
I have a long running SQL query inside a page that I've sped up
I have been running a mammoth SQL query that is as so: select SessionID,
I recently discovered that a sql query that was running fine earlier is now

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.