У нас вы можете посмотреть бесплатно Excluding Values from the LIKE Statement in SQL или скачать в максимальном доступном качестве, видео которое было загружено на ютуб. Для загрузки выберите вариант из формы ниже:
Если кнопки скачивания не
загрузились
НАЖМИТЕ ЗДЕСЬ или обновите страницу
Если возникают проблемы со скачиванием видео, пожалуйста напишите в поддержку по адресу внизу
страницы.
Спасибо за использование сервиса ClipSaver.ru
Discover how to effectively exclude specific values in SQL `LIKE` statements, ensuring more accurate query results when working with client descriptions. --- This video is based on the question https://stackoverflow.com/q/68122955/ asked by the user 'dingaro' ( https://stackoverflow.com/u/12242085/ ) and on the answer https://stackoverflow.com/a/68123074/ provided by the user 'Serg' ( https://stackoverflow.com/u/6219979/ ) at 'Stack Overflow' website. Thanks to these great users and Stackexchange community for their contributions. Visit these links for original content and any more details, such as alternate solutions, latest updates/developments on topic, comments, revision history etc. For example, the original title of the Question was: How to exclude values from like statement Also, Content (except music) licensed under CC BY-SA https://meta.stackexchange.com/help/l... The original Question post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license, and the original Answer post is licensed under the 'CC BY-SA 4.0' ( https://creativecommons.org/licenses/... ) license. If anything seems off to you, please feel free to write me at vlogize [AT] gmail [DOT] com. --- Excluding Values from the LIKE Statement in SQL: A Practical Guide When working with SQL Server, crafting a precise query can make a significant difference in dataset retrieval. Have you ever needed to filter out results that contain specific unwanted words while still making sure you include those that contain a certain substring? If so, you're not alone! This guide dives into how to achieve that using the LIKE statement in SQL, complete with a practical example. Understanding the Problem Let’s say you have a table which associates clients with their descriptions. Here's a simplified version of what your table might look like: clientdescriptionAdam Juhone Adam JuhJorge Bennertg Jorge BenneAnn SmithAnn 11.20Judy ForJudy For twoYou want to filter results to only include those descriptions that contain the client names as substrings but also exclude certain undesired words (like "one" or "two"). In this scenario, if we apply the condition using a LIKE statement, we'll end up with unwanted results unless we take further measures. Solution: Filtering Unwanted Values To resolve this, you can use a combination of the LIKE operator and a subquery that checks for the existence of any forbidden words within descriptions. Here is how you can shape your SQL query: The SQL Query [[See Video to Reveal this Text or Code Snippet]] Breaking It Down LIKE Statement: The initial condition checks if the description contains the client name by positioning the client string within the % wildcards. This signifies that there may be any character(s) before or after the client name. NOT EXISTS Clause: The second part of the condition is crucial. This ensures that if any value in our badwords table matches the description, that row will be excluded from the results. badwords Table: You will need a separate table called badwords which lists all the words you wish to filter out. For instance, this table might look like: wordonetwoFinal Result With the above query, if you run it against our example data, the result will be filtered to show only: clientdescriptionJorge Bennertg Jorge BenneThis approach ensures you effectively select records that meet both criteria: containing the client’s name while avoiding those with unwanted words. Conclusion Using the LIKE statement along with a NOT EXISTS clause is a powerful way to refine your SQL queries. By utilizing these features, you can create complex conditions that help fetch the precise data you need while excluding unwanted entries. If you find yourself often needing to exclude specific terms from your results, consider maintaining a badwords table with your most common exclusions, which will simplify your queries moving forward. By keeping your SQL queries accurate and efficient, you ensure cleaner data and better insights from your analyses. Happy querying!