SQL query problems

Source: Internet
Author: User
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?

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.