<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>MySQL - TheCodeBuzz</title>
	<atom:link href="https://thecodebuzz.com/category/mysql/feed/" rel="self" type="application/rss+xml" />
	<link>https://thecodebuzz.com</link>
	<description>Best Practices for Software Development</description>
	<lastBuildDate>Thu, 15 Feb 2024 00:38:17 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://thecodebuzz.com/wp-content/uploads/2022/11/cropped-android-chrome-512x512-1-1-51x51.jpg</url>
	<title>MySQL - TheCodeBuzz</title>
	<link>https://thecodebuzz.com</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>MySQL Query String contains with examples</title>
		<link>https://thecodebuzz.com/mysql-query-string-contains-examples/</link>
					<comments>https://thecodebuzz.com/mysql-query-string-contains-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 03 Feb 2024 03:41:04 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[MySQL Query String contains]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=30022</guid>

					<description><![CDATA[<p>MySQL Query String contains with examples Today in this article, we will see how to use MySQL query string contains with few examples. MySQL Query String contains with examples Query Pattern Above, we are getting the columns COLUMN-A where &#8220;COLUMN-B&#8221; contains &#60;search- fields&#62; from MySQL table TABLE-O Example In the above example, we are getting [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/mysql-query-string-contains-examples/">MySQL Query String contains with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading">MySQL Query String contains with examples</h1>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="176" height="119" src="https://www.thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains.png" alt="Mysql query string contains example" class="wp-image-30024" style="width:280px;height:auto"/></figure>



<p>Today in this article, we will see how to use MySQL query string contains with few examples.</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-mysql-query-string-contains-with-examples">MySQL Query String contains with examples</a><ul><li><a href="#aioseo-command-pattern">Query Pattern</a></li><li><a href="#aioseo-example">Example</a></li></ul></li><li><a href="#aioseo-mysql-string-contains-multiple-words">MySQL string contains multiple words</a><ul><li><a href="#aioseo-example">Example</a></li></ul></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-mysql-query-string-contains-with-examples">MySQL Query String contains with examples</h2>



<h3 class="wp-block-heading" id="aioseo-command-pattern">Query Pattern</h3>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">


SELECT 

`COLUMN-A` ,

FROM `TABLE-O` 

WHERE `COLUMN-B` 

LIKE &#039;%&lt;search-fields&gt;%&#039;




</pre></div>


<p>Above, we are getting the columns COLUMN-A where &#8220;COLUMN-B&#8221; contains &lt;search- fields&gt; from MySQL table TABLE-O</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example"><br>Example</h3>



<p></p>


<div class="wp-block-syntaxhighlighter-code "><pre class="brush: csharp; title: ; notranslate">
SELECT 
`post_name` , 
`post_title`

FROM `_ZRZ_posts` 

WHERE `post_content` 

LIKE &#039;%mailkit%&#039;
</pre></div>


<figure class="wp-block-image size-full"><img fetchpriority="high" decoding="async" width="787" height="607" src="https://www.thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains-example.jpg" alt="Mysql query string contains ,mysql string contains multiple words" class="wp-image-30026" srcset="https://thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains-example.jpg 787w, https://thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains-example-300x231.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains-example-768x592.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2024/02/mysql-query-string-contains-example-674x520.jpg 674w" sizes="(max-width: 787px) 100vw, 787px" /></figure>



<p></p>



<p></p>



<p>In the above example, we are getting all the website post details where the post contains matching fields called &#8220;<em><strong>mailkit</strong></em>&#8220;.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-mysql-string-contains-multiple-words">MySQL string contains multiple words</h2>



<p></p>



<p>We can verify mysql contains multiple values query as below.</p>



<p></p>



<p>One can use the OR or AND operator to combine multiple values as needed.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example">Example</h3>



<p></p>



<pre class="wp-block-preformatted">SELECT `post_name` , `post_title` FROM `_ZRZ_posts` WHERE `post_content` LIKE '%<strong>mailkit</strong>%' <strong>OR </strong>'<strong>smtp</strong>';</pre>



<p></p>



<pre class="wp-block-preformatted">SELECT `post_name` , `post_title` FROM `_ZRZ_posts` WHERE `post_content` LIKE '%<strong>mailkit</strong>%' <strong>AND </strong>'<strong>smtp</strong>';</pre>



<p>In the above example, we get the names of all posts where the post contains matching fields called &#8220;mailkit&#8221; or &#8220;SMTP&#8221; in the content.</p>



<p></p>



<p> </p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p>



<p></p>



<p></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/mysql-query-string-contains-examples/">MySQL Query String contains with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/mysql-query-string-contains-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>SQL &#8211; Time or Date range query with examples</title>
		<link>https://thecodebuzz.com/sql-time-or-date-range-query-with-examples/</link>
					<comments>https://thecodebuzz.com/sql-time-or-date-range-query-with-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sat, 11 Nov 2023 22:54:58 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=28837</guid>

					<description><![CDATA[<p>SQL &#8211; Time or Date range query with examples Today in this article, we will cover SQL &#8211; Time or Date range query with examples. We will see how to get records with greater than date or less than date/time or in between 2 given dates. We will see SQL queries for greater than OR [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/sql-time-or-date-range-query-with-examples/">SQL – Time or Date range query with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>SQL &#8211; Time or Date range query with examples</strong></h1>



<figure class="wp-block-image size-full is-resized"><img decoding="async" width="710" height="519" src="https://www.thecodebuzz.com/wp-content/uploads/2023/11/specific-time-range-query-in-sql-server.jpg" alt="sql-server-datetime-range-query" class="wp-image-28839" style="aspect-ratio:1.3680154142581888;width:738px;height:auto" srcset="https://thecodebuzz.com/wp-content/uploads/2023/11/specific-time-range-query-in-sql-server.jpg 710w, https://thecodebuzz.com/wp-content/uploads/2023/11/specific-time-range-query-in-sql-server-300x219.jpg 300w" sizes="(max-width: 710px) 100vw, 710px" /></figure>



<p>Today in this article, we will cover SQL &#8211; Time or Date range query with examples.</p>



<p></p>



<p>We will see how to get records with greater than date or less than date/time or in between 2 given dates.</p>



<p></p>



<p>We will see SQL queries for greater than OR  Less than or equal to dates or specific time ranges.</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-sql-query-less-than-specific-date-range">SQL Query &#8211; Less Than Specific Date Range</a><ul><li><a href="#aioseo-command">Command</a></li><li><a href="#aioseo-example">Example</a></li></ul></li><li><a href="#aioseo-sql-query-greater-than-specific-date-range">SQL Query &#8211; Greater Than Specific Date Range</a><ul><li><a href="#aioseo-command">Command</a></li><li><a href="#aioseo-example">Example</a></li></ul></li><li><a href="#aioseo-sql-query-greater-than-and-less-than-specific-date-range">SQL Query &#8211; Greater Than and Less Than Specific Date Range</a><ul><li><a href="#aioseo-command">Command</a></li><li><a href="#aioseo-example">Example</a></li></ul></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-sql-query-less-than-specific-date-range">SQL Query &#8211; Less Than Specific Date Range</h2>



<p></p>



<p>If you need to retrieve records where the date is greater than a specific date, please use the below query command.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-command">Command </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT *
FROM [Table_Name]
WHERE [Data_Column_Name] &lt;  [Date]

</pre>



<p>In this query:</p>



<ul class="wp-block-list">
<li><code>SELECT *</code>: Retrieves all records from the table.</li>



<li><code>FROM Table_Name</code> : Specifies the table from which to pick data.</li>



<li><code>WHERE Data_Column_Name</code> <code>&lt; </code> [Date]:  Defines the date range query to get the records where Data_Column_Name is greater than the specified date.</li>
</ul>



<p></p>



<h3 class="wp-block-heading" id="aioseo-example">Example </h3>



<pre class="wp-block-preformatted">SELECT *
FROM EMPLOYEE
WHERE DATE_JOINED &lt; '2023-11-11'
</pre>



<p>The above query returns all the columns of the EMPLOYEE table where DATE_JOINED is greater than the specified date i.e &#8216;2023-11-11&#8217;</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-sql-query-greater-than-specific-date-range">SQL Query &#8211; Greater Than Specific Date Range</h2>



<p></p>



<p>If you need to retrieve records where the date is greater than a specific date, please use the below query command.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-command">Command </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT *
FROM [Table_Name]
WHERE [Data_Column_Name] &gt;  [Date]
</pre>



<h3 class="wp-block-heading" id="aioseo-example">Example </h3>



<pre class="wp-block-preformatted">SELECT *
FROM EMPLOYEE
WHERE DATE_JOINED &gt;  '2023-07-15'


</pre>



<h2 class="wp-block-heading" id="aioseo-sql-query-greater-than-and-less-than-specific-date-range">SQL Query &#8211; Greater Than and Less Than Specific Date Range</h2>



<p></p>



<p>If you need to retrieve records between two dates where the date is greater than a specific date and less than a specific date, please use the below query command.</p>



<p></p>



<p>We will use <strong>BETWEEN </strong>operator to get records between 2 dates.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-command">Command </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT *
FROM [Table_Name]
WHERE [Data_Column_Name] BETWEEN [Date1] AND [Date2];
</pre>



<h3 class="wp-block-heading" id="aioseo-example">Example </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT *
FROM EMPLOYEE
WHERE DATE_JOINED BETWEEN '2022-01-01' AND '2023-01-01';
</pre>



<p>In this query:</p>



<ul class="wp-block-list">
<li><code>SELECT *</code>: Get all columns from the specified table.</li>



<li><code>FROM EMPLOYEE</code> : Specifies the table from which to read the data</li>



<li><code>WHERE DATE_JOINED BETWEEN '2022-01-01' AND '2023-01-01'</code>: This query will return all the employees who joined between Jan 1, 2022, and Jan 1, 2023 year.</li>
</ul>



<p></p>



<p>That&#8217;s all! Happy coding!</p>



<p></p>



<p>Does this help you fix your issue? </p>



<p></p>



<p>Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/sql-time-or-date-range-query-with-examples/">SQL – Time or Date range query with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/sql-time-or-date-range-query-with-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Pagination in SQL &#8211; Guidelines with examples</title>
		<link>https://thecodebuzz.com/pagination-in-sql-guidelines-examples/</link>
					<comments>https://thecodebuzz.com/pagination-in-sql-guidelines-examples/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Mon, 12 Jun 2023 04:28:00 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Pagination in SQL]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=27638</guid>

					<description><![CDATA[<p>Pagination in SQL with guidelines and examples Pagination in SQL is the procedure of retrieving a subset of data results from a query in smaller, manageable chunks or pages. This is often used when dealing with large result sets to improve performance and provide a better user experience. Pagination in SQL is used to retrieve [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/pagination-in-sql-guidelines-examples/">Pagination in SQL – Guidelines with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading" id="aioseo-pagination-in-sql-with-guidelines-and-examples"><strong>Pagination in SQL with guidelines and examples</strong></h1>



<figure class="wp-block-image size-full is-resized"><img loading="lazy" decoding="async" width="710" height="519" src="https://www.thecodebuzz.com/wp-content/uploads/2023/06/Pagination-in-SQL-Guidelines-with-examples.jpg" alt="Pagination in SQL " class="wp-image-27685" style="width:620px;height:453px" srcset="https://thecodebuzz.com/wp-content/uploads/2023/06/Pagination-in-SQL-Guidelines-with-examples.jpg 710w, https://thecodebuzz.com/wp-content/uploads/2023/06/Pagination-in-SQL-Guidelines-with-examples-300x219.jpg 300w" sizes="auto, (max-width: 710px) 100vw, 710px" /></figure>



<p>Pagination in SQL is the procedure of retrieving a subset of data results from a query in smaller, manageable chunks or pages. </p>



<p></p>



<p>This is often used when dealing with large result sets to improve performance and provide a better user experience. </p>



<p></p>



<p>Pagination in SQL is used to retrieve and display a subset of data results at a time, rather than fetching the entire result set in a single query. There are several reasons why pagination is commonly used,</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-benefits-of-pagination-in-sql">Benefits of Pagination in SQL</a><ul><li><a href="#aioseo-performance-optimization">Pagination SQL &#8211;  Performance Optimization</a></li><li><a href="#aioseo-content-base-loading-in-ux-guidelines">Pagination SQL &#8211; Content-Base Loading in UX guidelines</a></li><li><a href="#aioseo-reduced-network-latency">Reduced Network Latency</a></li></ul></li><li><a href="#aioseo-better-resource-management">Better Resource Management</a></li><li><a href="#aioseo-scalability">Scalability</a><ul><li><a href="#aioseo-data-streaming-and-real-time-updates">Data streaming and Real-Time Updates</a></li></ul></li><li><a href="#aioseo-pagination-in-sql-with-examples">Pagination in SQL using &#8211; LIMIT and OFFSET</a></li><li><a href="#aioseo-pagination-in-sql-with-examples-row_number">Pagination in SQL using &#8211; ROW_NUMBER()</a></li><li><a href="#aioseo-row_number-vs-limit-offset">LIMIT/OFFSET Vs ROW_NUMBER</a></li></ul></div>



<p></p>



<h2 class="wp-block-heading" id="aioseo-benefits-of-pagination-in-sql"><strong>Benefits of Pagination in SQL </strong></h2>



<p></p>



<h3 class="wp-block-heading" id="aioseo-performance-optimization">Pagination SQL &#8211;  Performance Optimization</h3>



<p></p>



<p>Fetching all the data at once can be inefficient and resource-intensive. It could literally break your system or crash your services or System. </p>



<p></p>



<p>When dealing with large result sets, by implementing pagination, you can retrieve or display a smaller chunk of data, reducing the amount of data transferred over the network and improving query performance.</p>



<p></p>



<p><strong><em>Example</em></strong>: Most services failure generally occurs due to a huge set of data request on the server in one GO.</p>



<p></p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-content-base-loading-in-ux-guidelines">Pagination SQL &#8211; Content-Base Loading in UX guidelines </h3>



<p></p>



<p>To improve user experience, pagination allows users to navigate through the data in a more manageable and convenient manner. </p>



<p></p>



<p>It provides a way to break down the results into smaller, organized pages, making it easier for users to locate and access the information they need.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-reduced-network-latency">Reduced Network Latency</h3>



<p></p>



<p>Repeatedly fetching large data in a single query can result in increased network latency on the database, especially in distributed systems or when dealing with remote databases. </p>



<p></p>



<p>However, actual network latency and data transfer time depend on the <em><strong>underlying network infrastructure and the size of the dataset being retrieved</strong></em>.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-better-resource-management">Better Resource Management</h2>



<p></p>



<p>Resources like memory GB or CPU cost you money. With pagination, you only load a portion of the result set into memory at a time, reducing the memory footprint and allowing for better resource utilization.</p>



<p></p>



<p>When working with memory-constrained environments, fetching and storing small amounts of data will help the system&#8217;s performance and responsiveness.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-scalability">Scalability</h2>



<p></p>



<p>Pagination enables applications to scale efficiently by fetching and processing data in <a href="https://www.thecodebuzz.com/mongodb-implement-batch-chunks-crud-update-operations/" target="_blank" rel="noopener" title="MongoDB – C#.NET Implement Batch or Chunk for CRUD operations">smaller chunks</a>. </p>



<p></p>



<p>This approach minimizes the impact on system resources, making it easier to handle increasing user loads and larger datasets without overwhelming the database or application servers.</p>



<p></p>



<h3 class="wp-block-heading" id="aioseo-data-streaming-and-real-time-updates">Data streaming and Real-Time Updates</h3>



<p></p>



<p>Data streaming in chunks helps can in providing real-time updates with delta changes efficiently.</p>



<p></p>



<p>When new <a href="https://www.thecodebuzz.com/insert-data-table-into-sql-server-database/">data is added or modified in the database,</a> pagination allows you to refresh the displayed results by fetching a new page without reloading the entire result set. This can be useful for displaying live or frequently updated data in real time.</p>



<p></p>



<p></p>



<p>Overall, pagination in SQL provides a balance between query performance, resource utilization, and user experience. </p>



<p></p>



<p>It allows for efficient data retrieval, reduces network and memory overhead, and enables users to navigate and access data in a more organized and manageable way.</p>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-pagination-in-sql-with-examples"><strong>Pagination in SQL using &#8211; LIMIT and OFFSET</strong></h2>



<p></p>



<p>Let&#8217;s assume you have a table called <code>customers</code> with columns <code>customer_id</code>, <code>first_name</code>, and <code>last_name</code>, and you want to retrieve the customers in pages of 10 results each.</p>



<p></p>



<p>Let&#8217;s assume here our Page size is 10 i.e. it can hold 10 records in each page.</p>



<p></p>



<p><strong>Retrieve the first 10 Records</strong></p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><code>SELECT * 
FROM Employee
ORDER BY Employee_id
<strong>LIMIT 10 OFFSET 0;</strong>
</code></pre>



<p></p>



<p>In the above query, </p>



<p></p>



<ul class="wp-block-list">
<li><code><strong>LIMIT 10</strong></code> specifies that we want to retrieve a maximum of 10 rows, and </li>



<li><code>OFFSET 0</code> indicates that we start from the first row (0-based index). </li>



<li>This retrieves the first page of 10 customers sorted by <code>customer_id</code>.</li>
</ul>



<p></p>



<p><strong>Retrieve</strong> <strong>the next 10 Records</strong></p>



<p>To retrieve the second page, you can use an <code>OFFSET</code> value of 10:</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><code><code>SELECT * 
FROM Employee
ORDER BY Employee_id
<strong>LIMIT 10 OFFSET 10;</strong>
</code></code></pre>



<ul class="wp-block-list">
<li>The above query skips the first 10 rows and fetches the next 10 rows, giving you the second page of customers.</li>
</ul>



<p></p>



<p>You can continue this pattern to retrieve subsequent pages by incrementing the <code>OFFSET</code> value. </p>



<p></p>



<p></p>



<p><strong>Retrieve the third set of 10 Records and so on</strong></p>



<p></p>



<p>For example, to retrieve the third page, you would use an <code>OFFSET</code> value of 20</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size"><code>SELECT * 
FROM Employee
ORDER BY Employee_id
<strong>LIMIT 10 OFFSET 20;</strong>

</code></pre>



<p>So just by adjusting the <strong><em><code>OFFSET</code> </em></strong>value and keeping the <em><strong><code>LIMIT</code> </strong></em>value <strong>constant</strong>, you can navigate through the entire result data set and retrieve data in pages efficiently.</p>



<p></p>



<p></p>



<p>It&#8217;s important to note that when using pagination with <code>LIMIT</code> and <code>OFFSET</code>, the performance may degrade as you go deeper into the result set. </p>



<p></p>



<p>This is because the database needs to skip a certain number of rows before returning the requested page.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-pagination-in-sql-with-examples-row_number"><strong>Pagination in SQL using &#8211; ROW_NUMBER()</strong></h2>



<p></p>



<p>This is an alternative pagination technique such as using keyset pagination or the <code><strong>ROW_NUMBER</strong>()</code> the function can provide better performance and scalability.</p>



<p></p>



<p>Pagination using the <code>ROW_NUMBER()</code> function is a common technique that assigns a sequential number to each row in the result set, which is used to divide the data into pages. </p>



<pre class="wp-block-preformatted">SELECT *
FROM (SELECT *, ROW_NUMBER() OVER (ORDER BY Employee_id) AS row_num
  FROM Employess) AS numbered_rows
WHERE row_num BETWEEN 11 AND 20;</pre>



<p></p>



<p>In the above query, </p>



<ul class="wp-block-list">
<li>The inner query uses the <code>ROW_NUMBER()</code> function to assign a row number to each row in the <code>customers</code> table, ordered by the <code>customer_id</code>. </li>



<li>The result of the inner query is then aliased as <code>numbered_rows</code>.</li>



<li>The outer query filters the result to retrieve rows where the row_num falls within the desired page range. For example &#8211; we retrieve rows 11 to 20, effectively representing the second page of data with a page size of 10.</li>



<li>You can adjust the <code>BETWEEN</code> clause to specify different page ranges to retrieve the desired subsets of data. For example, <code>BETWEEN 1 AND 10</code> retrieves the first page, <code>BETWEEN 21 AND 30</code> retrieves the third page, and so on.</li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-row_number-vs-limit-offset"><strong>LIMIT/OFFSET Vs ROW_NUMBER</strong></h2>



<p></p>



<ul class="wp-block-list">
<li>Using <code>ROW_NUMBER()</code> for pagination offers more flexibility and control compared to the <code>LIMIT</code> and <code>OFFSET</code> approach. </li>



<li>It avoids the performance degradation often associated with large <code>OFFSET</code> values.</li>



<li>Allows you to efficiently navigate through the result set by directly selecting the desired page range.</li>



<li>R<code>OW_NUMBER()</code> let you combine query with other SQL clauses, such as <code>ORDER BY</code>, <code>WHERE</code>, and <code>JOIN</code>, providing more refinement and filtering the paginated results</li>
</ul>



<p></p>



<p>Additionally, it&#8217;s recommended to have appropriate <strong><em>indexes </em></strong>on the columns used in the <code>ORDER BY</code> clause to improve the efficiency of pagination queries.</p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/pagination-in-sql-guidelines-examples/">Pagination in SQL – Guidelines with examples</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/pagination-in-sql-guidelines-examples/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>T-SQL- Pad left and Pad right functions in SQL</title>
		<link>https://thecodebuzz.com/t-sql-pad-left-pad-right-functions-sql-mysql/</link>
					<comments>https://thecodebuzz.com/t-sql-pad-left-pad-right-functions-sql-mysql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 26 Mar 2023 00:57:49 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[lpad in sql server]]></category>
		<category><![CDATA[lpad in sql server example]]></category>
		<category><![CDATA[right padding in sql server]]></category>
		<category><![CDATA[sql pad left 0]]></category>
		<category><![CDATA[sql pad left with spaces]]></category>
		<category><![CDATA[sql padding]]></category>
		<category><![CDATA[sql server left pad zeros]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=26350</guid>

					<description><![CDATA[<p>T-SQL- Pad left and Pad right functions in SQL Today in this article, we will see how to add Pad left and Pad right functions in SQL with examples. Learn how to add Pad left and Pad right functions in SQL with examples, including adding leading zeros to SQL fields. We have below EmployeeID which [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/t-sql-pad-left-pad-right-functions-sql-mysql/">T-SQL- Pad left and Pad right functions in SQL</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>T-SQL- Pad left and Pad right functions in SQL</strong></h1>



<figure class="wp-block-image size-full"><img loading="lazy" decoding="async" width="710" height="373" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/T-SQL-pad-left-pad-right.jpg" alt="sql pad left with spaces,
" class="wp-image-26369" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/T-SQL-pad-left-pad-right.jpg 710w, https://thecodebuzz.com/wp-content/uploads/2023/03/T-SQL-pad-left-pad-right-300x158.jpg 300w" sizes="auto, (max-width: 710px) 100vw, 710px" /></figure>



<p>Today in this article, we will see how to add Pad left and Pad right functions in SQL with examples.</p>



<p></p>



<p>Learn how to add Pad left and Pad right functions in SQL with examples, including adding leading zeros to SQL fields.</p>



<p></p>



<p>We have below EmployeeID which is defined as a <a href="https://www.thecodebuzz.com/regex-mongodb-array-string-field-value-length-greater-than-less-than/">string type and length</a> of 4 characters.</p>



<p></p>



<p><strong>Example </strong></p>



<pre class="wp-block-preformatted has-large-font-size">1

123

1234</pre>



<p></p>



<h2 class="wp-block-heading">SQL- Pad right logic to add trailing zeros to SQL Field</h2>



<p></p>



<p>The expected output is as below,</p>



<p></p>



<pre class="wp-block-preformatted has-large-font-size">1000

1200

1230

1234</pre>



<p></p>



<h3 class="wp-block-heading">SQL Query pattern</h3>



<p></p>



<pre class="wp-block-preformatted">SELECT LEFT (&lt;SQL FIELD> +'0000', 4) FROM &lt;Table Name>;</pre>



<p></p>



<h3 class="wp-block-heading">Example </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT LEFT ([EmployeeID]+'0000', 4) FROM Table_2;</pre>



<p></p>



<figure class="wp-block-image size-large is-style-default"><a href="https://www.thecodebuzz.com/t-sql-pad-left-and-pad-right-functions-in-sql-mysql/" target="_blank" rel="noreferrer noopener"><img loading="lazy" decoding="async" width="1024" height="328" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-trailing-zero-pad-right-mysql-1024x328.jpg" alt="SQL Pad left and right " class="wp-image-26359" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-trailing-zero-pad-right-mysql-1024x328.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-trailing-zero-pad-right-mysql-300x96.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-trailing-zero-pad-right-mysql-768x246.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-trailing-zero-pad-right-mysql-785x251.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption class="wp-element-caption">#image_title</figcaption></figure>



<p></p>



<h2 class="wp-block-heading">SQL- Pad left zeros i.e to add leading zeros to SQL Field</h2>



<p></p>



<p>The expected output is as below,</p>



<p></p>



<pre class="wp-block-preformatted has-large-font-size">0001

0012

0123

1234</pre>



<p></p>



<h3 class="wp-block-heading">SQL Query pattern</h3>



<p></p>



<pre class="wp-block-preformatted">SELECT RIGHT('0000' + &lt;SQL FIELD&gt;, 4) FROM &lt;Table Name&gt;</pre>



<p></p>



<h3 class="wp-block-heading">Example </h3>



<p></p>



<pre class="wp-block-preformatted">SELECT RIGHT ('0000'+ [EmployeeID], 4) FROM Table_2;</pre>



<p></p>



<p></p>



<figure class="wp-block-image size-large"><a href="https://www.thecodebuzz.com/t-sql-pad-left-and-pad-right-functions-in-sql-mysql/" target="_blank" rel="noreferrer noopener"><img loading="lazy" decoding="async" width="1024" height="351" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-leading-zero-pad-left-pad-right-mysql-1024x351.jpg" alt="Pad left and Pad right functions in SQL,sql pad left with spaces,
<a href=" class="wp-image-26361" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-leading-zero-pad-left-pad-right-mysql-1024x351.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-leading-zero-pad-left-pad-right-mysql-300x103.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-leading-zero-pad-left-pad-right-mysql-768x263.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/03/SQL-Add-leading-zero-pad-left-pad-right-mysql-785x269.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></a><figcaption class="wp-element-caption">#image_title</figcaption></figure>



<p></p>



<p>That&#8217;s all! Happy coding!</p>



<p></p>



<p>Does this help you fix your issue? </p>



<p></p>



<p>Do you have any better solutions or suggestions? Please sound off your comments below.</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/t-sql-pad-left-pad-right-functions-sql-mysql/">T-SQL- Pad left and Pad right functions in SQL</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/t-sql-pad-left-pad-right-functions-sql-mysql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
		<item>
		<title>Concatenate Texts from Multiple Rows in SQL</title>
		<link>https://thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/</link>
					<comments>https://thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Sun, 19 Mar 2023 01:01:45 +0000</pubDate>
				<category><![CDATA[MySQL]]></category>
		<category><![CDATA[NoSQL]]></category>
		<category><![CDATA[SQL]]></category>
		<category><![CDATA[Concatenate Texts from Multiple Rows in SQL]]></category>
		<guid isPermaLink="false">https://www.thecodebuzz.com/?p=26403</guid>

					<description><![CDATA[<p>Concatenate texts from multiple rows in SQL Today in this article, we will see how to Concatenate texts from multiple rows in SQL. It&#8217;s pretty simple to combine multiple rows in SQL and create Concatenate texts using the STRING_AGG function. Let&#8217;s take an example below. Here I have a sample table with the Bank code [&#8230;]</p>
<p>The post <a href="https://thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/">Concatenate Texts from Multiple Rows in SQL</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></description>
										<content:encoded><![CDATA[<h1 class="wp-block-heading"><strong>Concatenate texts from multiple rows in SQL</strong></h1>



<figure class="wp-block-image size-full"><a href="https://www.thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/" target="_blank" rel="noreferrer noopener"><img loading="lazy" decoding="async" width="710" height="373" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/convert-multiple-rows-into-one-with-comma-as-separator.jpg" alt="" class="wp-image-26410" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/convert-multiple-rows-into-one-with-comma-as-separator.jpg 710w, https://thecodebuzz.com/wp-content/uploads/2023/03/convert-multiple-rows-into-one-with-comma-as-separator-300x158.jpg 300w" sizes="auto, (max-width: 710px) 100vw, 710px" /></a></figure>



<p>Today in this article, we will see how to Concatenate texts from multiple rows in SQL.</p>



<p></p>



<p>It&#8217;s pretty simple to combine multiple rows in SQL and create Concatenate texts using the STRING_AGG function.</p>



<p></p>



<div class="wp-block-aioseo-table-of-contents"><ul><li><a href="#aioseo-example">Example</a></li><li><a href="#aioseo-expected-output">Expected output</a></li><li><a href="#aioseo-command">What is STRING_AGG</a></li><li><a href="#aioseo-command">Command</a></li></ul></div>



<p></p>



<p>Let&#8217;s take an example below. Here I have a sample table with the Bank code and Name of the employee matching the bank code.</p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-example"><strong>Example </strong></h2>



<p></p>



<figure class="wp-block-image size-full"><a href="https://www.thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql" target="_blank" rel="noreferrer noopener"><img loading="lazy" decoding="async" width="474" height="400" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql.jpg" alt="Concatenate texts from multiple rows in SQL" class="wp-image-26404" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql.jpg 474w, https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-a-single-text-string-in-sql-300x253.jpg 300w" sizes="auto, (max-width: 474px) 100vw, 474px" /></a></figure>



<h2 class="wp-block-heading" id="aioseo-expected-output">Expected output </h2>



<p></p>



<p>Here we will try to get out as below,</p>



<p></p>



<pre class="wp-block-preformatted has-medium-font-size">FC100   X, Y, Z
FC345   A, P, S</pre>



<p></p>



<p></p>



<h2 class="wp-block-heading" id="aioseo-command">What is STRING_AGG</h2>



<p></p>



<ul class="wp-block-list">
<li>The aggregate function STRING AGG concatenates every expression from every row into a single string.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>The implicit conversion of expression values to string types is done before concatenation.</li>
</ul>



<p></p>



<ul class="wp-block-list">
<li>The implicit conversion to strings adheres to the standards for converting data types.</li>
</ul>



<p></p>



<h2 class="wp-block-heading" id="aioseo-command">Command </h2>



<p></p>



<pre class="wp-block-preformatted">STRING_AGG ( expression, separator ) [ &lt;order_clause&gt; ] &lt;order_clause&gt; ::= WITHIN GROUP ( ORDER BY &lt;order_by_expression_list&gt; [ ASC | DESC ] )</pre>



<p></p>



<p>Example:</p>



<p></p>



<p></p>



<figure class="wp-block-image size-large"><img loading="lazy" decoding="async" width="1024" height="402" src="https://www.thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-single-text-string-in-sql-1024x402.jpg" alt="STRING_AGG " class="wp-image-26405" srcset="https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-single-text-string-in-sql-1024x402.jpg 1024w, https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-single-text-string-in-sql-300x118.jpg 300w, https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-single-text-string-in-sql-768x302.jpg 768w, https://thecodebuzz.com/wp-content/uploads/2023/03/concatenate-text-from-multiple-rows-into-single-text-string-in-sql-785x308.jpg 785w" sizes="auto, (max-width: 1024px) 100vw, 1024px" /></figure>



<p></p>



<p></p>



<p></p>



<p style="font-size:18px">Do you have any <strong>comments or ideas or any better </strong>suggestions to share?</p>



<p class="has-small-font-size"></p>



<p style="font-size:18px">Please sound off your comments below.</p>



<p class="has-medium-font-size"></p>



<p class="has-medium-font-size"><strong>Happy Coding </strong>!!</p>



<p></p>



<hr>



<p class=""></p>



<p class="has-background" style="background-color:#b6d9ac;font-size:18px"><br>Please <strong><em>bookmark </em></strong>this page and <em><strong>share </strong></em>it with your friends.                                                    Please <a href="https://www.thecodebuzz.com/subscription/" target="_blank" rel="noreferrer noopener"><em><mark style="background-color:rgba(0, 0, 0, 0)" class="has-inline-color has-luminous-vivid-orange-color"><strong>Subscribe</strong> </mark></em></a>to the blog to receive notifications on freshly published (2025) best practices and guidelines for software design and development.</p>




<br>



<hr>



<p class=""></p>



<p></p>



<p></p><p>The post <a href="https://thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/">Concatenate Texts from Multiple Rows in SQL</a> first appeared on <a href="https://thecodebuzz.com">TheCodeBuzz</a>.</p>]]></content:encoded>
					
					<wfw:commentRss>https://thecodebuzz.com/concatenate-texts-from-multiple-rows-in-sql/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
