[Be careful !] A large amount of duplicate data will appear in multiple like queries.

Source: Internet
Author: User
Multiple like queries may result in a large amount of duplicate data. No problem description two table tables: usersidusername1andy2jack3leo4kimi table caridtitleuseridchnname1bmw7501 BMW 2bmw5301 BMW 3bmw2 BMW 4benzc21 Mercedes

Multiple like queries may result in a large number of duplicate data records without ======================================== = problem description =========================================================== two table tables usersid username1 andy2 jack3 leo4 kimi table carid title userid chnname1 bmw750 1 bmw 2 bmw530 1 bmw 3 bmw 2 bmw 4 benzc2 1 Mercedes-Benz

A large amount of duplicate data will appear in multiple like queries. <无>
================================== Problem description ======== ============================== two table tables usersid username1 andy2 jack3 leo4 kimi table carid title userid chnname1 bmw750 1 bmw 2 bmw530 1 bmw 3 bmw 2 bmw 4 benzc2 1 Mercedes-Benz 5 benzE3 2 Mercedes-Benz SQL: select * from. *, B. * from car a inner join username B on. userid = B. id now you need to add like query condition query title similar to bmw's select * from. *, B. * from car a inner join username B on. userid = B. id and. title like '% The bmw % 'statement returns three results. Correct. However, if I add a like condition, the title cannot be queried. The title is similar to the bmw chnname and similar to the bmw select * from. *, B. * from car a inner join username B on. userid = B. id and. title like '% bmw %' or. chnname like '% BMW %' so that you will get a lot of duplicate data ====================== = the above SQL statement is equivalent to select. *, B. * from car a inner join username B on. userid = B. id AND. title like '% bmw %' UNION ALLselect. *, B. * from car a inner join username B on. chnname like '% BMW %' ================================ solution = ==================================== add () in the like condition () or use where1.select * from. *, B. * from car a inner join username B on. userid = B. id and (. title like '% bmw %' or. chnname like '% BMW %') 2. select. *, B. * from car a inner join username B on. userid = B. id where. title like '% bmw %' or. chnname like '% BMW %'

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.