Have data in the database like the below table.
| ID | Data |
| 1 | 4963,4960 |
| 2 | 4961,4963 |
User input values can be like 4963,4960 or 4960,4963 both should match.
Please share the SQL query which matches both cases.
Thanks
Have data in the database like the below table.
| ID | Data |
| 1 | 4963,4960 |
| 2 | 4961,4963 |
User input values can be like 4963,4960 or 4960,4963 both should match.
Please share the SQL query which matches both cases.
Thanks
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Naimish MakwanaPosted Mar 1, 2023, 10:20 AM
Hello Vishal,
Try below
Thanks
Naimish Makwana
Vishal JoshiPosted Mar 2, 2023, 5:00 AM
Hello Naimish and Henry,
Thanks for the answers. Naimish answer matched my requirement.
Henry your answer also matches but we need to create a dynamic query based on user input.
Again thank you so much.
horald HenryPosted Mar 1, 2023, 1:02 PM
To find comma-separated values in a string, you can use FIND_IN_SET() function. Here's a sample query that should work in both scenarios:
Using the FIND IN SET function, this query first determines if the values '4963' and '4960' are present in the 'Data' column. The first criterion will be met if they are present. If not, it uses the second condition to check the reverse order '4960' and '4963'.