3

I want to make a MySql selection for a period of time. but i didn't figure it out how to make it correctly.

this is what i tried

SELECT * FROM rapoarte WHERE DATE(ziua) BETWEEN 2010-01-12 AND 2011-01-14

Can you please help?

thanks, Sebastian

sebastian
  • 1,528
  • 8
  • 26
  • 38

2 Answers2

6

If performance is an issue I would avoid using DATE in this way as it will prevent efficient usage of an index and will result in a full scan. For small tables this might not be a problem but if your table is large you will probably find that this gives better performance:

SELECT *
FROM rapoarte
WHERE ziua >= '2010-01-12'
AND ziua < '2010-01-15'
Mark Byers
  • 811,555
  • 193
  • 1,581
  • 1,452
  • +1 This is the better method, however the first > must be a >=. In addition, I don't think the "00:00:00" is necessary. – AndreKR Nov 08 '10 at 08:16
  • @AndreKR: Yes, you are right about the >=. Fixed now, thanks. – Mark Byers Nov 08 '10 at 08:17
  • @MarkByers I didn't get the performance part. How can performance get affected using Date? reference : http://stackoverflow.com/questions/4382892/whats-mysqls-between-performance-over – Sudeep Gujar Sep 16 '16 at 13:03
1
SELECT * FROM rapoarte WHERE DATE(ziua) BETWEEN "2010-01-12" AND "2011-01-14"
AndreKR
  • 32,613
  • 18
  • 106
  • 168