Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing Multiple ids to single parameter in mysql

Tags:

mysql

I have table emloyee with following data.

Id    Name     Country   

1     John      USA

2     Smith     USA

3     Jack      IND

4     Lory      UK

5     Miller    USA

I want to get result by calling stored procedure like this

call getEmployeeDetailsByCountry('IND,UK');

Result:
Id    Name     Country   

3     Jack      IND

4     Lory      UK

My Procedure is

select * from employee
where if( (LOCATE(',','IND,USD')>0),
Country in (concat('\'',REPLACE('IND,USD', ',', '\',\''),'\''))
, Country in ('IND,USD'));

Here it replaces 'IND,USD' to 'IND','USD'. But result is no rows.... Can anyone help me to find..... thank you

like image 517
RUPA Avatar asked Nov 25 '25 20:11

RUPA


1 Answers

Use FIND_IN_SET instead of IN

    SELECT * 
FROM product
WHERE FIND_IN_SET(country, 'IND,USD');

Try this i think this will solve your problem

like image 156
rakesh pakkam Avatar answered Nov 27 '25 10:11

rakesh pakkam



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!