php_begins Posted August 29, 2011 Share Posted August 29, 2011 Hi, Can I have a comma separated values in WHERE clause of an MYSQL select statement? Something like this, $id=100,102; SELECT id,name from tablename WHERE id='$id'; I need to display all ids where the names where id=$id. The $id variable is a dynamic comma separated ids. Link to comment https://forums.phpfreaks.com/topic/245978-mysql-query-where-clause-with-comma-separated-values/ Share on other sites More sharing options...
Maq Posted August 29, 2011 Share Posted August 29, 2011 Comma separated values should be avoided, it's poor design and causes a lot of headache. If you have to check these then you can use IN() http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html#function_in Link to comment https://forums.phpfreaks.com/topic/245978-mysql-query-where-clause-with-comma-separated-values/#findComment-1263289 Share on other sites More sharing options...
php_begins Posted August 29, 2011 Author Share Posted August 29, 2011 Thanks,why do u think its not effiecient? Link to comment https://forums.phpfreaks.com/topic/245978-mysql-query-where-clause-with-comma-separated-values/#findComment-1263292 Share on other sites More sharing options...
fenway Posted September 1, 2011 Share Posted September 1, 2011 Thanks,why do u think its not effiecient? It *is* inefficient -- it's lazy storage in 99% of the use cases. Link to comment https://forums.phpfreaks.com/topic/245978-mysql-query-where-clause-with-comma-separated-values/#findComment-1264285 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.