SQL query problems table structure & nbsp; idnamenasid & nbsp; 1nas11, 2,3 & nbsp; 2nas22, 3,4 & nbsp; 3nas32, 3, 5 I now have two nasids: 1, 2. I want to query the problems related to the nasid containing 1 SQL query in the above three data items
Table structure
Id name nasid
1 nas1 1, 2, 3
2 nas2 2, 3, 4
3 nas3 2, 3, 5
I now have two nasids: 1, 2
I want to query all the data whose nasid contains at least one number.
How to write this SQL statement? please give me some ideas and try like, but the efficiency is too low.
------ Solution --------------------
Select * from table where find_in_set ('1', nasid) or find_in_set ('2', nasid)
------ Solution --------------------
Full table scan, which is not efficient
------ Solution --------------------
Use regular expressions ..
SELECT * FROM '000000' WHERE '000000' REGEXP '(1 | 2) +'
After a test, you can go to the test database of our system and check it out.
------ Solution --------------------
Regular expressions are a little simpler, but a little more complicated is not powerful. Of course, existing functions must be used.
To amani11: How did you perform full table scan?