0

I need to display the rows that matches any one of the numbers that are separated by commas.

This is my query,

 query("select * from sample_table where sample_id IN ('1,3,6,4,7,9') ");

My query must select the table containing when any one of the numbers matches.

Unknown.geeko
  • 73
  • 1
  • 2
  • 7
  • http://stackoverflow.com/questions/3653462/is-storing-a-delimited-list-in-a-database-column-really-that-bad/3653574 _I store my data the totally wrong way, and now I'm having problems using it. It's complicated/difficult/too slow/doesn't work right! Can someone help?_ The answer is Yes - fix your data so it's stored properly to begin with, and all those problems using it go away. You don't have to optimize difficult things when they're not difficult in the first place – e4c5 Dec 16 '16 at 09:54

2 Answers2

0

if the sample_id field type is int then: query("select * from sample_table where sample_id IN (1,3,6,4,7,9) ");

if its type is varchar then query("select * from sample_table where sample_id IN ('1','3','6','4','7','9') ");

Azad khan
  • 79
  • 7
0

Your query is query("select * from sample_table where sample_id IN ('1,3,6,4,7,9') ");

If you change to this query("select * from sample_table where sample_id IN (1,3,6,4,7,9) "); than it will work. You only need to remove single quotes ie ('1,3,6,4,7,9') to (1,3,6,4,7,9)

Saurav Kuwar
  • 1
  • 1
  • 2