{"id":22357,"date":"2025-05-13T11:16:59","date_gmt":"2025-05-13T05:46:59","guid":{"rendered":"https:\/\/www.pickl.ai\/blog\/?p=22357"},"modified":"2025-05-13T11:17:00","modified_gmt":"2025-05-13T05:47:00","slug":"mysql-substring","status":"publish","type":"post","link":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/","title":{"rendered":"MySQL SUBSTRING() Function: A Complete Guide"},"content":{"rendered":"\n<p><strong>Summary: <\/strong>The MySQL SUBSTRING() function extracts substrings from strings using specified start positions and optional lengths. It supports both positive and negative indexing and can be used in SELECT and WHERE clauses. Mastering SUBSTRING() enables efficient text data manipulation, transformation, and analysis in MySQL databases.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_82_2 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Introduction\" >Introduction<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#_MySQL_SUBSTRING_Function\" >&nbsp;MySQL SUBSTRING() Function<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Basic_Usage\" >Basic Usage<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Using_Only_Start_Position\" >Using Only Start Position<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Using_Negative_Start_Position\" >Using Negative Start Position<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Using_in_Table_Queries\" >Using in Table Queries<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Alternate_Syntax\" >Alternate Syntax<\/a><ul class='ez-toc-list-level-4' ><li class='ez-toc-heading-level-4'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Examples\" >Examples<\/a><\/li><\/ul><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Tips_and_Best_Practices_for_Using_MySQL_SUBSTRING\" >Tips and Best Practices for Using MySQL SUBSTRING()<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Understand_Indexing_1-Based_Not_0-Based\" >Understand Indexing: 1-Based, Not 0-Based<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Omitting_the_Length_Parameter\" >Omitting the Length Parameter<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-12\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Using_Negative_Values_for_Start_and_Length\" >Using Negative Values for Start and Length<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-13\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Check_Your_Start_Position_and_Length\" >Check Your Start Position and Length<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-14\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Conclusion\" >Conclusion<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-15\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Frequently_Asked_Questions\" >Frequently Asked Questions<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-16\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#What_is_the_Syntax_for_the_SUBSTRING_Function\" >What is the Syntax for the SUBSTRING() Function?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-17\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#What_Happens_if_the_Length_Parameter_is_Omitted\" >What Happens if the Length Parameter is Omitted?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-18\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#Can_You_Use_SUBSTRING_in_a_WHERE_Clause\" >Can You Use SUBSTRING() in a WHERE Clause?<\/a><\/li><\/ul><\/li><\/ul><\/nav><\/div>\n<h2 id=\"introduction\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Introduction\"><\/span><strong>Introduction<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Extracting specific parts of text is a common requirement in database management, reporting, and data transformation. <a href=\"https:\/\/www.pickl.ai\/blog\/difference-between-sql-and-mysql\/\">MySQL<\/a>, one of the world\u2019s most popular relational database systems, provides a powerful tool for this purpose: the SUBSTRING() function.<\/p>\n\n\n\n<p>Whether you are parsing customer data, cleaning up records, or manipulating strings for analytics, understanding how to use SUBSTRING() efficiently can make your SQL queries more effective and your data workflows smoother.<\/p>\n\n\n\n<p>This comprehensive guide covers everything you need to know about the MySQL SUBSTRING() function-its syntax, usage, practical examples, tips, and best practices. By the end, you\u2019ll be able to handle a wide range of string extraction tasks with confidence.<\/p>\n\n\n\n<p><strong>&nbsp;Key Takeaways<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SUBSTRING() extracts parts of strings using start and optional length parameters.<\/li>\n\n\n\n<li>Negative start values count positions from the end of the string.<\/li>\n\n\n\n<li>Omitting length returns the substring from the start to the string\u2019s end.<\/li>\n\n\n\n<li>SUBSTRING() works in SELECT and WHERE clauses for flexible queries.<\/li>\n\n\n\n<li>It\u2019s interchangeable with SUBSTR() and MID() in MySQL.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"mysql-substring-function\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"_MySQL_SUBSTRING_Function\"><\/span><strong>&nbsp;MySQL SUBSTRING() Function<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<figure class=\"wp-block-image size-full\"><img fetchpriority=\"high\" decoding=\"async\" width=\"877\" height=\"564\" src=\"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10.png\" alt=\"MySQL SUBSTRING() Function\" class=\"wp-image-22361\" srcset=\"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10.png 877w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-300x193.png 300w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-768x494.png 768w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-110x71.png 110w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-200x129.png 200w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-380x244.png 380w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-255x164.png 255w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-550x354.png 550w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-800x514.png 800w, https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image10-150x96.png 150w\" sizes=\"(max-width: 877px) 100vw, 877px\" \/><\/figure>\n\n\n\n<p>The SUBSTRING() function in MySQL is designed to extract a portion of a string (substring) from a specified position, with an optional length parameter. It is widely used for data manipulation, formatting, and transformation tasks.<\/p>\n\n\n\n<p>The SUBSTRING() function extracts a substring from a string, starting at any position you specify. If you provide a length, it returns that many characters; if not, it returns the rest of the string from the starting position.<\/p>\n\n\n\n<p><strong>Equivalents:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>SUBSTRING() is functionally identical to SUBSTR() and MID() in MySQL.<\/li>\n<\/ul>\n\n\n\n<p><strong>Syntax:<\/strong><strong><br><\/strong> MySQL offers two syntaxes for the SUBSTRING() function:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXfoou7r8XTkebHq4BvyTPxG89vayyrdw4hwHqQFIeKxNLMDtZCQ78ZconuuxovSWa2j744-gs1_PpI8g-DCDgSkpspakjFxaMWa8q6GAIJOEjsbSrTZ7cWrJr8XJXX38dPpKDUbIQ?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"syntax for MySQL SUBSTRING() function\"\/><\/figure>\n\n\n\n<ul class=\"wp-block-list\">\n<li>start: The position to begin extraction (positive for left-to-right, negative for right-to-left).<\/li>\n\n\n\n<li>length (optional): Number of characters to extract.<\/li>\n<\/ul>\n\n\n\n<h2 id=\"basic-usage\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Basic_Usage\"><\/span><strong>Basic Usage<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The most basic form of SUBSTRING() extracts a substring starting at a specific position:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXe_98mpwCpBeRfOXlogqASePq5TB_tDD91UxMjSQIpTqU2UBHiT7GSDfux8xAJ-0ehwoOU3-HTXzZR3afYtjBK2BYQ10IjxOH1qvjMYn9WSCdoXKkalSdy_yD2Q5nTkLwd4CaWR?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"code for basic form of SUBSTRING() extracts a substring starting at a specific position.\"\/><\/figure>\n\n\n\n<p>This extracts 9 characters starting from the 7th character of the string.<\/p>\n\n\n\n<h3 id=\"using-only-start-position\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Only_Start_Position\"><\/span><strong>Using Only Start Position<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you omit the length parameter, the function returns the substring from the start position to the end:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXdZPVfqYArTO-pcQU6XHsNxuAe3xXYz04SpYdv9-SKlp8glRXDnrftAf3oWH2TSmddAdH7_pyQXLPOhBdPWhVtWsXQ2xh3WTS2_8CkUXXUT3vyAqROrtWthK2HgOW3juZjjumOgww?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"function returns the substring from the start position to the end\"\/><\/figure>\n\n\n\n<p>Here, the substring starts at position 11 and continues to the end of the string.<\/p>\n\n\n\n<h3 id=\"using-negative-start-position\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Negative_Start_Position\"><\/span><strong>Using Negative Start Position<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>A negative start value means counting from the end of the string:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXcjtLPLlPduYHPUVN46BK9Kq8xiOgvFdfPGIkMMNAbqYf6jqc6cfFBP-rWIg_Uolychk_970LyMEnCIGV1ZvKVvo8ki4nhT94DQ1pGH3NijXx0ccwsCQ1XPYmnjxeJYdDAPnrcB?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"negative start position\"\/><\/figure>\n\n\n\n<p>This starts 5 characters from the end and extracts 5 characters.<\/p>\n\n\n\n<h3 id=\"using-in-table-queries\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_in_Table_Queries\"><\/span><strong>Using in Table Queries<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>SUBSTRING() is often used to extract parts of column values:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXd1-slEGa9Tve-DaGMRlArvorpCO9C1Tkb_shNqSc9eQ5maDBm8Q6em6CA3MskPZM3p4AxMTDaVBgruKUrh7N9UDBBaJp-3fEAIGs7zXCtM_ASIsnvWrQit5cVhkCkO8j5-bzRa1g?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"SUBSTRING() is often used to extract parts of column values\"\/><\/figure>\n\n\n\n<p>This returns the original publisher name and a 5-character substring starting at the 4th character, but only for publishers in the USA.<\/p>\n\n\n\n<h3 id=\"alternate-syntax\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Alternate_Syntax\"><\/span><strong>Alternate Syntax<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>You can also use the FROM and FOR keywords:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXdZznMWQAog32c_Pzivg_cn9mF3F-fcA1MgJV6WnEBmDI-NnrAXlzUeipt7ktuKv0lBuE0A_YaQS6HxGJSBLE7yaG2k-b2vcpVvqNVmKMp6hU6ROd3956QAjErpFf5co17CVGR6oA?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"Alternate Syntax using the FROM and FOR keywords\"\/><\/figure>\n\n\n\n<p>This is functionally the same as the comma-separated syntax.<\/p>\n\n\n\n<h4 id=\"examples\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Examples\"><\/span><strong>Examples<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h4>\n\n\n\n<p><strong>Example 1: Extracting a Substring from a String<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXcHbRZh0tPbb1FiEplnpEawt4VnNKr9KJ20D3qI3b30iJm2CHo7cNzqNH2r-scArTtHR-BKVqawcTaAO6UbWCLa-bK2WLZUmCkXBtnr2sMp8rswC8Atqpau7TgZRGQ-H1kxUi2j5Q?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"extraction of a Substring from a string\"\/><\/figure>\n\n\n\n<p>This extracts 3 characters starting from the 5th position.<\/p>\n\n\n\n<p><strong>Example 2: Extracting from the End<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXf8bGEO_qA2d4cYlMursc3Tw9phSi9e71lvVcJ3q_-ml2KlrJW6jeXb9R9koWLjnPWICM5f-V_Qt7a4e-eqWhkrdtqbMR7P_BPtuaQB_MsA6gEPODDeiSt_vRWqz7867x48iOEDwQ?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"extraction of a Substring from the end\"\/><\/figure>\n\n\n\n<p>Starts 5 characters from the end and extracts 5 characters.<\/p>\n\n\n\n<p><strong>Example 3: Extracting from a Table Column<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image\"><img decoding=\"async\" src=\"https:\/\/lh7-rt.googleusercontent.com\/docsz\/AD_4nXeLcj0IApCtw-veRjsEOgGfKZukn9TNkpRrFMictPzy379KHGarDjsCGHcyu9weEZX8H0fhrKbAb7J49DJOFrzrQ_Dj3fGEuFGuR9xevcJhWtOzBkhRcMPYVOPN1czBMwWtatFS?key=aai8EF6ptYqJ8jcLq8OJiLWO\" alt=\"extraction of a Substring from table column\"\/><\/figure>\n\n\n\n<h2 id=\"tips-and-best-practices-for-using-mysql-substring\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Tips_and_Best_Practices_for_Using_MySQL_SUBSTRING\"><\/span><strong>Tips and Best Practices for Using MySQL SUBSTRING()<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Mastering the SUBSTRING() function in MySQL can greatly enhance your ability to manipulate and extract data from strings. Here are the most important tips and best practices, along with common mistakes to avoid, to ensure you use this function effectively and efficiently:<\/p>\n\n\n\n<h3 id=\"understand-indexing-1-based-not-0-based\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Understand_Indexing_1-Based_Not_0-Based\"><\/span><strong>Understand Indexing: 1-Based, Not 0-Based<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>In <a href=\"https:\/\/www.pickl.ai\/blog\/introduction-to-mysql\/\">MySQL<\/a>, the starting position for SUBSTRING() is 1-based. The first character in a string is at position 1, not 0.<\/p>\n\n\n\n<p>Example: SUBSTRING(&#8216;MySQL&#8217;, 2, 2) returns &#8216;yS&#8217; (characters at positions 2 and 3).<\/p>\n\n\n\n<h3 id=\"omitting-the-length-parameter\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Omitting_the_Length_Parameter\"><\/span><strong>Omitting the Length Parameter<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The length argument is optional. If you omit it, SUBSTRING() will return all characters from the start position to the end of the string.<\/p>\n\n\n\n<p>Example: SUBSTRING(&#8216;Hello, World!&#8217;, 8) returns &#8216;World!&#8217;.<\/p>\n\n\n\n<h3 id=\"using-negative-values-for-start-and-length\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Using_Negative_Values_for_Start_and_Length\"><\/span><strong>Using Negative Values for Start and Length<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Both the start and length parameters can be negative:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A negative start counts from the end of the string (-1 is the last character).<\/li>\n\n\n\n<li>A negative length returns the substring up to that many characters from the end.<\/li>\n<\/ul>\n\n\n\n<p>Example: SUBSTRING(&#8216;abcdef&#8217;, -3, 2) returns &#8216;de&#8217;.<\/p>\n\n\n\n<h3 id=\"check-your-start-position-and-length\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Check_Your_Start_Position_and_Length\"><\/span><strong>Check Your Start Position and Length<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Double-check the values you provide for start and length. An incorrect starting position or length can result in unexpected or empty results. If start is greater than the string\u2019s length, the result is an empty string. If length exceeds the remaining characters, it simply returns up to the end of the string.<\/p>\n\n\n\n<h2 id=\"conclusion\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Conclusion\"><\/span><strong>Conclusion<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>The MySQL SUBSTRING() function is a versatile and essential tool for anyone working with text data in databases. It allows you to extract, transform, and analyze string values efficiently, supporting a wide range of business and technical needs. By mastering its syntax, understanding its behavior with different parameters, and following best practices, you can unlock powerful data manipulation capabilities in your <a href=\"https:\/\/www.pickl.ai\/blog\/sql-views\/\">SQL workflows<\/a>.<\/p>\n\n\n\n<h2 id=\"frequently-asked-questions\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_Asked_Questions\"><\/span><strong>Frequently Asked Questions<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<h3 id=\"what-is-the-syntax-for-the-substring-function\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_is_the_Syntax_for_the_SUBSTRING_Function\"><\/span><strong>What is the Syntax for the SUBSTRING() Function?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>The syntax is SUBSTRING(string, start, length) or SUBSTRING(string FROM start FOR length). The length parameter is optional; omitting it returns the substring from the start position to the end.<\/p>\n\n\n\n<h3 id=\"what-happens-if-the-length-parameter-is-omitted\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_Happens_if_the_Length_Parameter_is_Omitted\"><\/span><strong>What Happens if the Length Parameter is Omitted?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>If you omit the length parameter, SUBSTRING() returns all characters from the specified start position to the end of the string.<\/p>\n\n\n\n<h3 id=\"can-you-use-substring-in-a-where-clause\" class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Can_You_Use_SUBSTRING_in_a_WHERE_Clause\"><\/span><strong>Can You Use SUBSTRING() in a WHERE Clause?<\/strong><span class=\"ez-toc-section-end\"><\/span><\/h3>\n\n\n\n<p>Yes, SUBSTRING() can be used in WHERE clauses to filter records based on substring values, such as matching or extracting parts of column data for conditional logic.<\/p>\n","protected":false},"excerpt":{"rendered":"Extract substrings from text in MySQL with flexible, powerful, and efficient SUBSTRING() function.\n","protected":false},"author":4,"featured_media":22363,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"om_disable_all_campaigns":false,"_monsterinsights_skip_tracking":false,"_monsterinsights_sitenote_active":false,"_monsterinsights_sitenote_note":"","_monsterinsights_sitenote_category":0,"footnotes":""},"categories":[613],"tags":[4005],"ppma_author":[2169,2605],"class_list":{"0":"post-22357","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-sql","8":"tag-mysql-substring"},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v20.3 (Yoast SEO v27.3) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>MySQL SUBSTRING : Everything You Need to Know<\/title>\n<meta name=\"description\" content=\"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"MySQL SUBSTRING() Function: A Complete Guide\" \/>\n<meta property=\"og:description\" content=\"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.pickl.ai\/blog\/mysql-substring\/\" \/>\n<meta property=\"og:site_name\" content=\"Pickl.AI\" \/>\n<meta property=\"article:published_time\" content=\"2025-05-13T05:46:59+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-13T05:47:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png\" \/>\n\t<meta property=\"og:image:width\" content=\"960\" \/>\n\t<meta property=\"og:image:height\" content=\"704\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Neha Singh, Anshul Jain\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Neha Singh\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/\"},\"author\":{\"name\":\"Neha Singh\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/#\\\/schema\\\/person\\\/2ad633a6bc1b93bc13591b60895be308\"},\"headline\":\"MySQL SUBSTRING() Function: A Complete Guide\",\"datePublished\":\"2025-05-13T05:46:59+00:00\",\"dateModified\":\"2025-05-13T05:47:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/\"},\"wordCount\":910,\"commentCount\":0,\"image\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/image5-8.png\",\"keywords\":[\"mysql substring\"],\"articleSection\":[\"SQL\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/\",\"url\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/\",\"name\":\"MySQL SUBSTRING : Everything You Need to Know\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/image5-8.png\",\"datePublished\":\"2025-05-13T05:46:59+00:00\",\"dateModified\":\"2025-05-13T05:47:00+00:00\",\"author\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/#\\\/schema\\\/person\\\/2ad633a6bc1b93bc13591b60895be308\"},\"description\":\"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/image5-8.png\",\"contentUrl\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2025\\\/05\\\/image5-8.png\",\"width\":960,\"height\":704,\"caption\":\"My SQL SUBSTRING() Function\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/mysql-substring\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"SQL\",\"item\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/category\\\/sql\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"MySQL SUBSTRING() Function: A Complete Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/\",\"name\":\"Pickl.AI\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/#\\\/schema\\\/person\\\/2ad633a6bc1b93bc13591b60895be308\",\"name\":\"Neha Singh\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/avatar_user_4_1717572961-96x96.jpg3d1a0d35d7a1a929f4a120e9053cbdb5\",\"url\":\"https:\\\/\\\/pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/avatar_user_4_1717572961-96x96.jpg\",\"contentUrl\":\"https:\\\/\\\/pickl.ai\\\/blog\\\/wp-content\\\/uploads\\\/2024\\\/06\\\/avatar_user_4_1717572961-96x96.jpg\",\"caption\":\"Neha Singh\"},\"description\":\"I\u2019m a full-time freelance writer and editor who enjoys wordsmithing. The 8 years long journey as a content writer and editor has made me relaize the significance and power of choosing the right words. Prior to my writing journey, I was a trainer and human resource manager. WIth more than a decade long professional journey, I find myself more powerful as a wordsmith. As an avid writer, everything around me inspires me and pushes me to string words and ideas to create unique content; and when I\u2019m not writing and editing, I enjoy experimenting with my culinary skills, reading, gardening, and spending time with my adorable little mutt Neel.\",\"url\":\"https:\\\/\\\/www.pickl.ai\\\/blog\\\/author\\\/nehasingh\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"MySQL SUBSTRING : Everything You Need to Know","description":"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.","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:\/\/www.pickl.ai\/blog\/mysql-substring\/","og_locale":"en_US","og_type":"article","og_title":"MySQL SUBSTRING() Function: A Complete Guide","og_description":"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.","og_url":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/","og_site_name":"Pickl.AI","article_published_time":"2025-05-13T05:46:59+00:00","article_modified_time":"2025-05-13T05:47:00+00:00","og_image":[{"width":960,"height":704,"url":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","type":"image\/png"}],"author":"Neha Singh, Anshul Jain","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Neha Singh","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#article","isPartOf":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/"},"author":{"name":"Neha Singh","@id":"https:\/\/www.pickl.ai\/blog\/#\/schema\/person\/2ad633a6bc1b93bc13591b60895be308"},"headline":"MySQL SUBSTRING() Function: A Complete Guide","datePublished":"2025-05-13T05:46:59+00:00","dateModified":"2025-05-13T05:47:00+00:00","mainEntityOfPage":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/"},"wordCount":910,"commentCount":0,"image":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","keywords":["mysql substring"],"articleSection":["SQL"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.pickl.ai\/blog\/mysql-substring\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/","url":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/","name":"MySQL SUBSTRING : Everything You Need to Know","isPartOf":{"@id":"https:\/\/www.pickl.ai\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#primaryimage"},"image":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#primaryimage"},"thumbnailUrl":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","datePublished":"2025-05-13T05:46:59+00:00","dateModified":"2025-05-13T05:47:00+00:00","author":{"@id":"https:\/\/www.pickl.ai\/blog\/#\/schema\/person\/2ad633a6bc1b93bc13591b60895be308"},"description":"Learn to use the MySQL SUBSTRING() function for efficient string manipulation. Explore its syntax, usage, examples, best practices, and FAQs.","breadcrumb":{"@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.pickl.ai\/blog\/mysql-substring\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#primaryimage","url":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","contentUrl":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","width":960,"height":704,"caption":"My SQL SUBSTRING() Function"},{"@type":"BreadcrumbList","@id":"https:\/\/www.pickl.ai\/blog\/mysql-substring\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.pickl.ai\/blog\/"},{"@type":"ListItem","position":2,"name":"SQL","item":"https:\/\/www.pickl.ai\/blog\/category\/sql\/"},{"@type":"ListItem","position":3,"name":"MySQL SUBSTRING() Function: A Complete Guide"}]},{"@type":"WebSite","@id":"https:\/\/www.pickl.ai\/blog\/#website","url":"https:\/\/www.pickl.ai\/blog\/","name":"Pickl.AI","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.pickl.ai\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/www.pickl.ai\/blog\/#\/schema\/person\/2ad633a6bc1b93bc13591b60895be308","name":"Neha Singh","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/pickl.ai\/blog\/wp-content\/uploads\/2024\/06\/avatar_user_4_1717572961-96x96.jpg3d1a0d35d7a1a929f4a120e9053cbdb5","url":"https:\/\/pickl.ai\/blog\/wp-content\/uploads\/2024\/06\/avatar_user_4_1717572961-96x96.jpg","contentUrl":"https:\/\/pickl.ai\/blog\/wp-content\/uploads\/2024\/06\/avatar_user_4_1717572961-96x96.jpg","caption":"Neha Singh"},"description":"I\u2019m a full-time freelance writer and editor who enjoys wordsmithing. The 8 years long journey as a content writer and editor has made me relaize the significance and power of choosing the right words. Prior to my writing journey, I was a trainer and human resource manager. WIth more than a decade long professional journey, I find myself more powerful as a wordsmith. As an avid writer, everything around me inspires me and pushes me to string words and ideas to create unique content; and when I\u2019m not writing and editing, I enjoy experimenting with my culinary skills, reading, gardening, and spending time with my adorable little mutt Neel.","url":"https:\/\/www.pickl.ai\/blog\/author\/nehasingh\/"}]}},"jetpack_featured_media_url":"https:\/\/www.pickl.ai\/blog\/wp-content\/uploads\/2025\/05\/image5-8.png","authors":[{"term_id":2169,"user_id":4,"is_guest":0,"slug":"nehasingh","display_name":"Neha Singh","avatar_url":"https:\/\/pickl.ai\/blog\/wp-content\/uploads\/2024\/06\/avatar_user_4_1717572961-96x96.jpg","first_name":"Neha","user_url":"","last_name":"Singh","description":"I\u2019m a full-time freelance writer and editor who enjoys wordsmithing. The 8 years long journey as a content writer and editor has made me relaize the significance and power of choosing the right words. Prior to my writing journey, I was a trainer and human resource manager. WIth more than a decade long professional journey, I find myself more powerful as a wordsmith. As an avid writer, everything around me inspires me and pushes me to string words and ideas to create unique content; and when I\u2019m not writing and editing, I enjoy experimenting with my culinary skills, reading, gardening, and spending time with my adorable little mutt Neel."},{"term_id":2605,"user_id":43,"is_guest":0,"slug":"anshuljain","display_name":"Anshul Jain","avatar_url":"https:\/\/pickl.ai\/blog\/wp-content\/uploads\/2024\/07\/avatar_user_43_1721992955-96x96.jpeg","first_name":"Anshul","user_url":"","last_name":"Jain","description":"Anshul Jain expertise lies in Predictive Modelling and Segmentation of data. Recently graduated from NSUT, Delhi in Instrumentation and Control Engineering. He has a keen interest in studying the Stock Market."}],"_links":{"self":[{"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/posts\/22357","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/comments?post=22357"}],"version-history":[{"count":1,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/posts\/22357\/revisions"}],"predecessor-version":[{"id":22366,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/posts\/22357\/revisions\/22366"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/media\/22363"}],"wp:attachment":[{"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/media?parent=22357"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/categories?post=22357"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/tags?post=22357"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.pickl.ai\/blog\/wp-json\/wp\/v2\/ppma_author?post=22357"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}