{"id":12401,"date":"2021-01-11T13:17:14","date_gmt":"2021-01-11T21:17:14","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=12401"},"modified":"2023-12-01T04:07:59","modified_gmt":"2023-12-01T12:07:59","slug":"sql-like","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/sql-like\/","title":{"rendered":"SQL Like: A How-To Guide"},"content":{"rendered":"\n<p><em>The SQL LIKE operator uses wildcards to find data similar to a particular pattern. You can use an underscore to substitute for a single character or a percentage sign to substitute zero, one, or multiple characters.<\/em><\/p>\n\n\n\n<p>Have you ever wanted to retrieve information from columns which contain a value similar to another? For instance, say you have a table called employees. Maybe you want to retrieve a list of employees whose title contains &#8220;Sales&#8221;.<\/p>\n\n\n\n<p>That\u2019s where the <em>SQL LIKE<\/em> operator comes into play. In this article, we\u2019ll break down how to use the <em>LIKE<\/em> operator on an <em>SQL<\/em> server to perform more specific queries.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL LIKE<\/h2>\n\n\n\n<p>The <em>SQL LIKE<\/em> operator finds records in a database whose column values match a particular pattern. Patterns are expressed using percent signs, underscores, and the text for which you are searching.<\/p>\n\n\n\n<p>For example, we can use <em>LIKE<\/em> to get all employees whose name ends in <em>S<\/em>, or whose title includes <em>Associate<\/em>.<\/p>\n\n\n\n<p>The <em>LIKE<\/em> operator makes use of wildcard characters to get data that matches a certain pattern. The two wildcards often used with the <em>LIKE<\/em> operator are as follows:<\/p>\n\n\n\n<p><em>_<\/em> \u2013 The underscore character represents a single character.<\/p>\n\n\n\n<p><em>%<\/em> \u2013 The percent sign represents zero, one, or more characters.<\/p>\n\n\n\n<p>Here is the structure of a query using the <em>LIKE<\/em> operator:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT column_name FROM table_name\nWHERE column_name LIKE pattern;<\/pre><\/div>\n\n\n\n<p>In this syntax, we use the LIKE operator in an <a href=\"https:\/\/careerkarma.com\/blog\/sql-select\/\">SQL SELECT statement<\/a>. You can use this operator in INSERT, UPDATE, and DELETE statements.<\/p>\n\n\n\n<p>Let\u2019s use an example to illustrate how <em>SQL LIKE<\/em> works. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">SQL LIKE Example<\/h2>\n\n\n\n<p>Say we have a table with information on the employees who work for a business. We want to retrieve the names and branches of every employee who works at a branch whose name starts with the letter <em>S<\/em>.<\/p>\n\n\n\n<p>To do this, we can use the following query:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name, branch FROM employees\nWHERE branch LIKE 'S%';<\/pre><\/div>\n\n\n\n<p>The SQL server database returns:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>name<\/td><td>branch<\/td><\/tr><tr><td>Mike<\/td><td>Stamford<\/td><\/tr><tr><td>Geoff<\/td><td>San Francisco<\/td><\/tr><tr><td>Hannah<\/td><td>San Francisco<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>(3 rows)<\/p>\n\n\n\n<p>The percent sign after the letter <em>S<\/em> tells our code that we want to get every branch whose name starts with the letter <em>S<\/em>. Our query returns every character string match.<\/p>\n\n\n\n<p>If we wanted to get the names and titles of every employee who is an associate, including senior associates, we could use this query:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name, title FROM employees\nWHERE title LIKE '%Associate%';<\/pre><\/div>\n\n\n\n<p>Our query finds all employees whose names match the pattern <em>\u2018%Associate%\u2019. <\/em>The query returns the following:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>name<\/td><td>title<\/td><\/tr><tr><td>Luke<\/td><td>Sales Associate<\/td><\/tr><tr><td>Mike<\/td><td>Sales Associate<\/td><\/tr><tr><td>Alexis<\/td><td>Sales Associate<\/td><\/tr><tr><td>Hannah<\/td><td>Sales Associate<\/td><\/tr><tr><td>Geoff<\/td><td>Senior Sales Associate<\/td><\/tr><\/tbody><\/table>\n\n\n\n<h2 class=\"wp-block-heading\">SQL NOT LIKE Example<\/h2>\n\n\n\n<p>We can use the <em>NOT LIKE<\/em> operator to select all records that do not meet a certain condition. The <em>NOT LIKE<\/em> statement is a combination of the SQL <em>NOT<\/em> and the <em>LIKE<\/em> statement. The <em>NOT<\/em> statement finds records which do not meet a condition.<\/p>\n\n\n\n<p>For example, we could use <em>NOT LIKE<\/em> to get the names of every employee whose name is not four characters long. Here is an SQL query we could use for this purpose:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>SELECT name FROM employees\nWHERE name NOT LIKE '____';<\/pre><\/div>\n\n\n\n<p>Our query will skip over every employee whose name is not four characters and return the rest.<\/p>\n\n\n\n<p>Each wildcard underscore represents one character. If a name is more or less than four characters long, it will not show up in our results set.<\/p>\n\n\n\n<p>Our database returns all records that match our search pattern:<\/p>\n\n\n\n<table class=\"wp-block-table course-info-table\"><tbody><tr><td>name<\/td><\/tr><tr><td>Alexis<br>Hannah<br>Jonah<br>Geoff<\/td><\/tr><\/tbody><\/table>\n\n\n\n<p>(4 rows)<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>The SQL LIKE operator lets you use patterns to find records in a database. You can use this record to find similar records without specifying an exact match which must be met. The LIKE operator appears in the WHERE section of an SQL statement.<\/p>\n\n\n\n<p>In this article, we discussed how you can use the <em>LIKE SQL<\/em> statement to make your queries more specific. We have also discussed how you can use the <em>NOT LIKE<\/em> statement to get information that does not meet specific rules.<\/p>\n\n\n\n<p>We have written an ultimate guide for SQL learners to help you acquire the knowledge you need to become a professional database developer. Check it out on our <a href=\"https:\/\/careerkarma.com\/blog\/learn-sql\/\">How to Learn SQL page<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"The SQL LIKE operator uses wildcards to find data similar to a particular pattern. You can use an underscore to substitute for a single character or a percentage sign to substitute zero, one, or multiple characters. Have you ever wanted to retrieve information from columns which contain a value similar to another? For instance, say&hellip;","protected":false},"author":240,"featured_media":12402,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17284],"tags":[],"class_list":{"0":"post-12401","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-sql"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"SQL","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>SQL Like: A How-To Guide: get information that matches a certain pattern<\/title>\n<meta name=\"description\" content=\"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/sql-like\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"SQL Like: A How-To Guide\" \/>\n<meta property=\"og:description\" content=\"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/sql-like\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2021-01-11T21:17:14+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T12:07:59+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1000\" \/>\n\t<meta property=\"og:image:height\" content=\"666\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"SQL Like: A How-To Guide\",\"datePublished\":\"2021-01-11T21:17:14+00:00\",\"dateModified\":\"2023-12-01T12:07:59+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/\"},\"wordCount\":663,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg\",\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sql-like\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/sql-like\/\",\"name\":\"SQL Like: A How-To Guide: get information that matches a certain pattern\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg\",\"datePublished\":\"2021-01-11T21:17:14+00:00\",\"dateModified\":\"2023-12-01T12:07:59+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/sql-like\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg\",\"width\":1000,\"height\":666},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/sql-like\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL\",\"item\":\"https:\/\/careerkarma.com\/blog\/sql\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"SQL Like: A How-To Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"SQL Like: A How-To Guide: get information that matches a certain pattern","description":"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/sql-like\/","og_locale":"en_US","og_type":"article","og_title":"SQL Like: A How-To Guide","og_description":"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.","og_url":"https:\/\/careerkarma.com\/blog\/sql-like\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2021-01-11T21:17:14+00:00","article_modified_time":"2023-12-01T12:07:59+00:00","og_image":[{"width":1000,"height":666,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"SQL Like: A How-To Guide","datePublished":"2021-01-11T21:17:14+00:00","dateModified":"2023-12-01T12:07:59+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/"},"wordCount":663,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg","articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/sql-like\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/sql-like\/","url":"https:\/\/careerkarma.com\/blog\/sql-like\/","name":"SQL Like: A How-To Guide: get information that matches a certain pattern","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg","datePublished":"2021-01-11T21:17:14+00:00","dateModified":"2023-12-01T12:07:59+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The SQL LIKE operator allows programmers to run more specific queries on a database. Learn about how the LIKE statement works in this article.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/sql-like\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/02\/SQL-LIKE.jpg","width":1000,"height":666},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/sql-like\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL","item":"https:\/\/careerkarma.com\/blog\/sql\/"},{"@type":"ListItem","position":3,"name":"SQL Like: A How-To Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12401","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=12401"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/12401\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/12402"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=12401"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=12401"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=12401"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}