Page 1 of 1

WHERE id=preselected id's?

Posted: Sun Apr 01, 2007 2:26 pm
by jmansa
I have a table with 8 users ( id= 1 - 8) and now I want the data for only id 1-4... How do I go about that? Tryid this... but something wrong!

Code: Select all

$result = mysql_query("SELECT * FROM electric2007 WHERE id=1-4 ORDER BY total desc")

Re: WHERE id=preselected id's?

Posted: Sun Apr 01, 2007 2:31 pm
by John Cartwright

Code: Select all

$result = mysql_query("SELECT * FROM electric2007 WHERE id IN (1,2,3,4) ORDER BY total desc")
is probably the simplest way

Posted: Sun Apr 01, 2007 9:21 pm
by aaronhall
Just to be picky, but if the id column is the primary key, you can use "id <= 4"... it's a little cleaner to use comparison operators for integer types (probably faster for lookups on larger tables, too).