Skip to content
Advertisement

How to select combination of 4 digits number from table columns?

I have a table as below:-

How can I select combination records when I pass in “2374” in my select statement?

My expected result should be

Advertisement

Answer

It is not easy to read, but it works:

What this code does is:
sorts the digits inside the column’s value, so 4237 becomes 2347 and compares against the (also) sorted sorted 2374–> 2347.
For this sorting I used group_concat().
See the demo.
Results:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement