Forum Moderators: open
I would like to Retrieve all value whatever match from our
Mysql Query give below..
select * from `tablename` where 1 AND `fields` in (1.0,1.5,1.6,1.9,143.0) ORDER BY `fields` ASC
but i am getting only
1.0
1.5
143.0
rows
i have also used
select * from `tablename` where 1 AND `fields` in ('1.0','1.5','1.6','1.9','143.0') ORDER BY `fields` ASC
but got same result
so plz give me any suggestion where I am wrong ....
I am appreciate for your support..
thank you
select * from `tablename` where 1 AND `fields` in ('1.0','1.5','1.6','1.9','143.0') ORDER BY `fields` ASC
"Where 1" is *usually* a dynamic programming approach when building a select. On it's own, it's only returns rows that are true; "select * from table where 1" is identical to "select * from table". For example,
$select = 'select * from table where 1';
(if some other condition exists, say an input from a search)
if ($keyword) { $select .= " and keyword like '%".$keyword."%'"; }
if ($username) { $select .= " and username ='".$username."'"; }
This is an easy way to develop a dynamic select, but as you see it's confusing reading the output. A more graceful approach:
if ($keyword) {
if ($where) { $where .= " and"; }
$where .= " keyword like '%".$keyword."%'";
}
if ($username) {
if ($where) { $where .= " and"; }
$where .= " and username ='".$username."'";
}
$select = "select * from table";
if ($where) { $select .= " where $where"; }
Eliminating "where 1" which is superfluous.
To answer the question, see blang's post, give us some examples of what is in the database that matches that field set and is not getting selected. Your select should "work" in either case. If the field is decimal, quotes are not needed, if it's varchar/text, quotes are needed.