April 1st, 2013, 10:42 PM
In order to get all ids between these 2 days, which one is prefered and why?
SELECT id WHERE date_added BETWEEN '2012-12-12' AND '2012-12-16'
SELECT id WHERE date_added >= '2012-12-12' AND date_added <= '2012-12-16'
April 1st, 2013, 11:54 PM
Same difference. First is easier to read, second may be easier to implement in code (like if you might not always need both endpoints).
April 2nd, 2013, 12:00 AM
depends, as requinix said, if you want to include the endpoints
Originally Posted by zxcvbnm
this difference does not apply if date_added is a DATE column, but consider what happens if it's a DATETIME column
the intent of the query is to return all rows on the 16th? or all rows up to but not including the 16th?
see Simply SQL, page 86
Last edited by r937; April 2nd, 2013 at 12:04 AM.