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. Quote 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 Quote 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? Quote 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. Quote 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
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.