Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get multiple id on multiple value in string with sql?

Tags:

sql

sql-server

I have one table like

tbl

---------------------
id  users   name
---------------------
1   2,3     acc1
2   4       acc2
3   2,4,1   acc3
4   4,1     acc4

In this table I want to get id and name by users i.e user [2] have which id and name

Suppose I pass user [2] then i get result id is 1 and 3 and name acc1 and acc3.

like image 706
Kinjal Patel Avatar asked Feb 15 '26 09:02

Kinjal Patel


1 Answers

Try this will work for you

    SELECT id,name FROM yourtablename WHERE `users` LIKE '%2%'; 
like image 66
Deepak Keynes Avatar answered Feb 18 '26 01:02

Deepak Keynes



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!