tags:

views:

55

answers:

3

If I would like to:

SELECT * FROM `Students`

...from age 0 to 20, how would I do this?

+7  A: 
select * from students where age between 0 and 20
duffymo
+4  A: 
SELECT *
FROM   Students
WHERE  Age >= 0 AND Age <= 20

MySQL has many operators from which you can choose.

James McNellis
A: 

You should be careful with "between". Different databased treat it differently. For instance in...

age between 0 and 20

... some DBs will gathers people with ages of 0-20 but some will gather people with ages 1-19 and so on.

Nate
MySQL is inclusive: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#operator_between
OMG Ponies
SQL Server is inclusive: http://technet.microsoft.com/en-us/library/ms187922.aspx
OMG Ponies
Oracle is inclusive: http://www.techonthenet.com/sql/between.php
OMG Ponies
Postgres is inclusive: http://www.postgresql.org/docs/8.2/static/functions-comparison.html
James McNellis
Sybase is inclusive: http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.help.ase_15.0.sqlug/html/sqlug/sqlug83.htm
James McNellis
SQLite is inclusive: http://www.sqlite.org/lang_expr.html (I figured, why stop with just Oracle, SQL Server, and MySQL :-D)
James McNellis
DB2 is inclusive: http://publib.boulder.ibm.com/infocenter/dzichelp/v2r2/index.jsp?topic=/com.ibm.db29.doc.sqlref/db2z_betweenpredicate.htm
Bob Kaufman
Microsoft Access is inclusive: http://office.microsoft.com/en-us/access/HP010322121033.aspx
Bob Kaufman
Never seen any DB that would understood between 0 and 20 as between 1 and 19. An example would be much appreciated.
quosoo
SQL-92 dictates that BETWEEN is inclusive: "X BETWEEN Y AND Z" is equivalent to "X>=Y AND X<=Z". (section 8.3)
Joe