SELECT * FROM users WHERE uid IN (SELECT doctors FROM MainPage WHERE Valid=1)
users
tableuid INT
Mainpage
tabledoctors text
with value as1,2,3,4,5
When I am running the above query, it is only resulting 1 row which is for uid = 1, however I wanted all the 5 rows. So in MySQL I used this query:
SELECT *
FROM users
JOIN MainPage ON FIND_IN_SET(uid, doctors)
WHERE Valid = 1;
It worked. I am trying to find an equivalent in SQL Server for FIND_IN_SET
to achieve the same result ?
The FIND_IN_SET() function returns the position of a string within a list of strings.
MySQL FIND_IN_SET() returns the position of a string if it is present (as a substring) within a list of strings. The string list itself is a string contains substrings separated by ',' (comma) character.
Finding value(s) from comma separated MySQL has REGEXP (Regular Express) function. REGEXP (MySQL find values in comma separated string) function can search or filer one or multiple string value in your field data.
This might work
SELECT *
FROM users u
WHERE EXISTS (
SELECT *
FROM MainPage
WHERE CONCAT(',',doctors,',') LIKE CONCAT('%,',u.uid,',%')
AND Valid = 1
)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With