{"id":280,"date":"2018-12-13T08:00:14","date_gmt":"2018-12-13T08:00:14","guid":{"rendered":"https:\/\/barkhane.com\/sql\/2018\/12\/13\/sql-like\/"},"modified":"2024-03-03T17:54:12","modified_gmt":"2024-03-03T17:54:12","slug":"sql-like","status":"publish","type":"post","link":"https:\/\/barkhane.com\/sql\/sql-like\/","title":{"rendered":"SQL LIKE"},"content":{"rendered":"<p>The LIKE operator is used in a WHERE clause to search for a specified pattern in a column.<\/p>\n<p>There are two wildcards used in conjunction with the LIKE operator:<\/p>\n<ul>\n<li>% &#8211; The percent sign represents zero, one, or multiple characters<\/li>\n<li>_ &#8211; The underscore represents a single character<\/li>\n<\/ul>\n<div class=\"w3-panel w3-note\">\n<p><strong>Note:<\/strong>\u00a0MS Access uses a question mark (?) instead of the underscore (_).<\/p>\n<\/div>\n<p>The percent sign and the underscore can also be used in combinations!<\/p>\n<p>&nbsp;<\/p>\n<h3>LIKE Syntax<\/h3>\n<div class=\"w3-example\">\n<div class=\"w3-code notranslate sqlHigh\">SELECT\u00a0<em>column1, column2, &#8230;<\/em><br \/>\nFROM\u00a0<em>table_name<\/em><br \/>\nWHERE\u00a0<em>columnN<\/em>\u00a0LIKE\u00a0<em>pattern<\/em>;<\/div>\n<\/div>\n<div><\/div>\n<div>\n<p>The basic syntax of % and _ is as follows \u2212<\/p>\n<pre class=\"result notranslate\">SELECT FROM table_name\nWHERE column LIKE \\'XXXX%\\'\n\nor \n\nSELECT FROM table_name\nWHERE column LIKE \\'%XXXX%\\'\n\nor\n\nSELECT FROM table_name\nWHERE column LIKE \\'XXXX_\\'\n\nor\n\nSELECT FROM table_name\nWHERE column LIKE \\'_XXXX\\'\n\nor\n\nSELECT FROM table_name\nWHERE column LIKE \\'_XXXX_\\'\n\n<\/pre>\n<h2>Example<\/h2>\n<p>The following table has a few examples showing the WHERE part having different LIKE clause with \\&#8217;%\\&#8217; and \\&#8217;_\\&#8217; operators \u2212<\/p>\n<table class=\"table table-bordered\">\n<tbody>\n<tr>\n<th>Sr.No.<\/th>\n<th>Statement &amp; Description<\/th>\n<\/tr>\n<tr>\n<td>1<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;60%\\&#8217;<\/b><\/p>\n<p>Finds any values that start with 60.<\/td>\n<\/tr>\n<tr>\n<td>2<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;%60%\\&#8217;<\/b><\/p>\n<p>Finds any values that have 60 in any position.<\/td>\n<\/tr>\n<tr>\n<td>3<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;_100%\\&#8217;<\/b><\/p>\n<p>Finds any values that have 100 in the second and third positions.<\/td>\n<\/tr>\n<tr>\n<td>4<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;6_%_%\\&#8217;<\/b><\/p>\n<p>Finds any values that start with 6 and are at least 3 characters in length.<\/td>\n<\/tr>\n<tr>\n<td>5<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;%9\\&#8217;<\/b><\/p>\n<p>Finds any values that end with 9.<\/td>\n<\/tr>\n<tr>\n<td>6<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;_8%3\\&#8217;<\/b><\/p>\n<p>Finds any values that have a 8 in the second position and end with a 3.<\/td>\n<\/tr>\n<tr>\n<td>7<\/td>\n<td><b>WHERE SALARY LIKE \\&#8217;7_ _ _9\\&#8217;<\/b><\/p>\n<p>Finds any values in a five-digit number that start with 7 and end with 9.<\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>The LIKE operator is used in a WHERE clause to search for a specified pattern in a column. There are [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"site-sidebar-layout":"default","site-content-layout":"","ast-site-content-layout":"default","site-content-style":"default","site-sidebar-style":"default","ast-global-header-display":"","ast-banner-title-visibility":"","ast-main-header-display":"","ast-hfb-above-header-display":"","ast-hfb-below-header-display":"","ast-hfb-mobile-header-display":"","site-post-title":"","ast-breadcrumbs-content":"","ast-featured-img":"","footer-sml-layout":"","ast-disable-related-posts":"","theme-transparent-header-meta":"","adv-header-id-meta":"","stick-header-meta":"","header-above-stick-meta":"","header-main-stick-meta":"","header-below-stick-meta":"","astra-migrate-meta-layouts":"default","ast-page-background-enabled":"default","ast-page-background-meta":{"desktop":{"background-color":"var(--ast-global-color-4)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"ast-content-background-meta":{"desktop":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"tablet":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""},"mobile":{"background-color":"var(--ast-global-color-5)","background-image":"","background-repeat":"repeat","background-position":"center center","background-size":"auto","background-attachment":"scroll","background-type":"","background-media":"","overlay-type":"","overlay-color":"","overlay-opacity":"","overlay-gradient":""}},"footnotes":""},"categories":[2],"tags":[],"class_list":["post-280","post","type-post","status-publish","format-standard","hentry","category-sql"],"_links":{"self":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/280","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/comments?post=280"}],"version-history":[{"count":0,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/posts\/280\/revisions"}],"wp:attachment":[{"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/media?parent=280"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/categories?post=280"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/barkhane.com\/sql\/wp-json\/wp\/v2\/tags?post=280"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}