"Daily Development" uses a variety of tools to implement SQL queries with no results for name

Source: Internet
Author: User
Tags mysql query

Address of this article

Share an outline:

1. The background of the matter

2. Workaround

3. Summary

1. The background of the matter

Now the name of 2000 data needs to be queried from the user table, and SQL writes

SELECT *  from User WHERE name    inch ('name1','name2',...  'name2000');

But out of the query results only 1997, indicating that there are 3 no results, there may be duplicate name, how to query out which 3 data is not the result or duplicate data?

2. Workaround

Guess the use of MySQL should also be found is that the 3 name no results, but for a moment did not think of it, had to use other methods.

The solution is this:

1) "MySQL results export"

First, there is text in the name of the result 1997 that will be queried (MySQL has already sorted the name) Mysql.log

2) "Find duplicate Data"

Then, the original data, using the shell command sort-u processing as Sort_unique.log with the original file Sort.log(also after sort processing) Vimdiff can be seen, Is there a duplicate name, and sure enough there are 1 duplicate name

3) "Find name with no return value"

Finally, Vimdiff, mysql.log and sort_unique.log(both achieve the same sort) can see exactly what name is in the data table The user did not return the

3. Summary

The first is that my MySQL query statement needs to be improved, and then, when a technology does not solve the problem, you can mix multiple technologies.

Like the shell mentioned above in the text processing, sorting, de-weight, contrast shows the advantages of unparalleled, much faster than the language processing such as PHP.

--In addition:

Have to know how to query directly with the SQL statement which name has no results of the classmate, also welcome the reply ha, learn to communicate together to improve, thank you ~

"Daily Development" uses a variety of tools to implement SQL queries with no results for name

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.