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 %'