<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Markme Dev</title>
    <description>The latest articles on DEV Community by Markme Dev (@marklouisalter).</description>
    <link>https://dev.to/marklouisalter</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1455840%2F9c9b8481-e9bd-45f8-84ea-54fb7d1e53de.png</url>
      <title>DEV Community: Markme Dev</title>
      <link>https://dev.to/marklouisalter</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marklouisalter"/>
    <language>en</language>
    <item>
      <title>OLAP: CUBE, ROLLUP, AND GROUPING SETS</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Thu, 09 May 2024 13:23:00 +0000</pubDate>
      <link>https://dev.to/marklouisalter/olap-cube-rollup-and-grouping-sets-50ek</link>
      <guid>https://dev.to/marklouisalter/olap-cube-rollup-and-grouping-sets-50ek</guid>
      <description>&lt;p&gt;In the realm of data analysis and business intelligence, OLAP (Online Analytical Processing) stands as a cornerstone technology, the facilitating multidimensional analysis of vast datasets. OLAP enables users to gain insights from data by analyzing it across &lt;em&gt;multiple dimensions&lt;/em&gt;, providing a comprehensive view of business metrics and performance.&lt;/p&gt;

&lt;p&gt;So by now we are going to discuss the three key features of OLAP which are the CUBE, ROLLUP, AND GROUPING SETS operators. That will play a pivotal roles in summarizing and aggregating data in various way.&lt;/p&gt;

&lt;p&gt;Let's first discuss the first one which is:&lt;/p&gt;

&lt;h2&gt;
  
  
  CUBE
&lt;/h2&gt;

&lt;p&gt;The cube is a powerful tool in OLAP, it can generate all possible combinations of dimension and their aggregate. It provides a comprehensive multidimensional view of the data by computing subtotals and totals for every combination of dimensions, enabling users to explore data from different perspectives and levels of granularity. &lt;/p&gt;

&lt;p&gt;Okay it's kind of technical on first but it will surely you will understand it when we are going to use it in query.&lt;/p&gt;

&lt;p&gt;Let's say we want to know the count of each person who are renting in a country, and what gender they are.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT country, 
       gender,
       COUNT(*)
FROM rentals
GROUP BY CUBE(country, gender) -- This one will group them by its country and gender.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the output of that will be this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| country    | gender   | COUNT(*) |
|------------|----------|----------|
| USA        | Male     | 100      |
| USA        | Female   | 150      |
| UK         | Male     | 120      |
| UK         | Female   | 130      |
| NULL       | Male     | 220      |  &amp;lt;-- Subtotal for Male across all countries
| NULL       | Female   | 280      |  &amp;lt;-- Subtotal for Female across all countries
| USA        | NULL     | 250      |  &amp;lt;-- Subtotal for USA across all genders
| UK         | NULL     | 250      |  &amp;lt;-- Subtotal for UK across all genders
| NULL       | NULL     | 500      |  &amp;lt;-- Grand total

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See each row represents a unique combination of "country" and "gender". That's the uses of &lt;strong&gt;CUBE&lt;/strong&gt; it will generate all possible combination base on what you aggregate. we have subtotal for each category and the grandtotal.&lt;/p&gt;




&lt;h2&gt;
  
  
  ROLLUP
&lt;/h2&gt;

&lt;p&gt;ROLLUP operator is used to generate hierarchical roll-up data. It computes subtotals for a predefined hierarchy of dimensions, typically moving from the most detailed level of granularity to the least detailed. It generates subtotals for each level of the hierarchy, producing a result set that includes subtotals for each combination of the specified columns, as well as grand totals. Its like more organize then lets make an example again.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT 
    country, 
    gender,
    COUNT(*) AS rental_count
FROM 
    rentals
GROUP BY 
    ROLLUP (country, gender);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the output will be this&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| country  | gender  | rental_count |
|----------|---------|--------------|
| NULL     | NULL    | 8            |  &amp;lt;-- Grand total
| NULL     | Male    | 3            |  &amp;lt;-- Subtotal for Male across all countries
| NULL     | Female  | 5            |  &amp;lt;-- Subtotal for Female across all countries
| USA      | NULL    | 3            |  &amp;lt;-- Subtotal for USA across all genders
| USA      | Male    | 2            |
| USA      | Female  | 1            |
| UK       | NULL    | 3            |  &amp;lt;-- Subtotal for UK across all genders
| UK       | Male    | 1            |
| UK       | Female  | 2            |

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you see its organize after the count of each category it will print the sub total of that then next will be the grand total. You may notice that the subtotals for each category often appear adjacent to the corresponding category rows. This is because the ROLLUP operator is designed to provide intuitive and readable output, placing subtotals in proximity to the data they summarize.&lt;/p&gt;

&lt;h2&gt;
  
  
  GROUPING SETS
&lt;/h2&gt;

&lt;p&gt;We use GROUPING SETS operator to group the groupings by the arguments we put inside its like grouping but the difference is that we can put as many group inside of that like &lt;br&gt;
GROUP BY GROUPING SET ((country, gender), (country), (gender)) We can group the data into combination of country and gender in the first argument and in second arguments we want to also group it in country only and so in the third argument.&lt;/p&gt;

&lt;p&gt;It's like we are combining 3 groups in 1 query which is first one is (country, gender), then the second is (country), then the third is (gender). so if you want to achieve the same result of that without using the grouping sets you need 3 query for that.&lt;/p&gt;

&lt;p&gt;Let's proceed to example of this grouping sets so we can understand it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT 
    country, 
    gender,
    COUNT(*) AS rental_count
FROM 
    rentals
GROUP BY 
    GROUPING SETS (country, gender, ());
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then the output would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;| country  | gender  | rental_count |
|----------|---------|--------------|
| NULL     | NULL    | 8            |  &amp;lt;-- Grand total
| NULL     | Male    | 3            |  &amp;lt;-- Subtotal for Male across all countries
| NULL     | Female  | 5            |  &amp;lt;-- Subtotal for Female across all countries
| USA      | NULL    | 3            |  &amp;lt;-- Subtotal for USA across all genders
| USA      | Male    | 2            |
| USA      | Female  | 1            |
| UK       | NULL    | 3            |  &amp;lt;-- Subtotal for UK across all genders
| UK       | Male    | 1            |
| UK       | Female  | 2            |
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So the explanation here is each unique combination of country, and gender is shown in the table then you are wondering why there is &lt;strong&gt;()&lt;/strong&gt; then that's a empty bracket meaning it will total all the count in the output but if we remove that it will only shown the sub total of each category.&lt;/p&gt;

&lt;p&gt;You are wondering why the CUBE and GROUPING SETS have a similarity then you're right but the cube is getting all the possible combination but the grouping sets is we can group as many as we want in one query.&lt;/p&gt;

&lt;p&gt;I know guys that's a lot to learn but if you keep using this in your query over the time you will understand each of this. Thanks a lot :)&lt;/p&gt;

</description>
      <category>database</category>
      <category>sql</category>
      <category>mysql</category>
      <category>postgres</category>
    </item>
    <item>
      <title>SQL's LIKE, ILIKE, and NOT LIKE: Beginner's Breakdown</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Tue, 07 May 2024 13:21:59 +0000</pubDate>
      <link>https://dev.to/marklouisalter/sqls-like-ilike-and-not-like-beginners-breakdown-3lfh</link>
      <guid>https://dev.to/marklouisalter/sqls-like-ilike-and-not-like-beginners-breakdown-3lfh</guid>
      <description>&lt;p&gt;&lt;strong&gt;Are you ready uncovering the power of SQL matching patterns?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the realm of database querying, grasping the matching pattern will make our query more accurate. It's akin to having a finely tuned radar, enabling us to pinpoint exactly what we're looking for amidst vast seas of data.&lt;/p&gt;

&lt;p&gt;In this blog you will learn how to use LIKE, ILIKE, and NOT LIKE. By understanding this this matching pattern we can transform our queries for searching into more precise tools, and more accurate extraction of what data we want to fetch.&lt;/p&gt;

&lt;p&gt;Without further ado lets start now the familarization on this pattern.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Understanding LIKE and ILIKE: What Sets Them Apart?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;At first glance, **LIKE **and **ILIKE **may seem interchangeable, both serving the purpose of pattern matching within SQL queries. However, a subtle yet significant distinction exists between these two operators.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LIKE&lt;/strong&gt; : This matching pattern allow us to search within text data. It operates on a &lt;em&gt;case-sensitive&lt;/em&gt; basis. meaning it distinguishes between uppercase and lowerchase characters. for example in query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT * FROM Product WHERE name LIKE '%APPLE%';&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The output will be all the name with APPLE word on it. its case sensitive so it will only select all the name where the APPLE is capital not included the small one.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;ILIKE&lt;/strong&gt; : This matching pattern allow us to search also within text data. but this one is &lt;strong&gt;case-insensitive&lt;/strong&gt; This operator performs pattern matching without regard to case sensitivity, making it a versatile tool for scenarios where we want our search to encompass all possible variations of letter casing. for example in query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT * FROM Product WHERE name ILIKE '%apple%'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The output will be all the name with apple word on it. with ILIKE would match not only 'apple' but also 'Apple' and 'APPLE.&lt;/p&gt;

&lt;p&gt;By understanding this subtle difference, we can wield LIKE and ILIKE with precision, So let's take advantage of this of how we gonna use it.&lt;/p&gt;

&lt;p&gt;The next is &lt;strong&gt;NOT LIKE&lt;/strong&gt; which is the inverse of LIKE and ILIKE that excluding the rows that match the specified pattern. for example in query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT * FROM product WHERE name NOT LIKE '%apple%'&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;It will exclude all the name with apple word on it. this is case-sensitive meaning it will only remove the 'apple' but not the 'Apple' and 'APPLE' word on it.&lt;/p&gt;

&lt;p&gt;Very basic right? now that you know the LIKE, ILIKE and NOT LIKE matching pattern why not using it in your matching pattern query? to make your extracting data more precision than before?&lt;/p&gt;

&lt;p&gt;That's it, and thanks for reading if you've made it this far!&lt;/p&gt;

</description>
      <category>sql</category>
      <category>mysql</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>Simplified SQL: Harnessing the Power of Aliases</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Fri, 03 May 2024 12:26:01 +0000</pubDate>
      <link>https://dev.to/marklouisalter/simplified-sql-harnessing-the-power-of-aliases-3j98</link>
      <guid>https://dev.to/marklouisalter/simplified-sql-harnessing-the-power-of-aliases-3j98</guid>
      <description>&lt;p&gt;Hello there its me again,&lt;/p&gt;

&lt;p&gt;So by now, you know what this is all about. But let me clarify once again that we are now going to discuss SQL aliasing for better readability and cleaner queries. It's helpful to use aliases if the names of your tables or columns are too long. We can use aliases for column names, tables, subqueries, and so on, but we'll focus on table and column names since this is more basic and easier to understand. and it also good to use alias if you are going to combining column.&lt;/p&gt;

&lt;p&gt;Here's the example of query that no alias.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvwrdr933n8yd3xihj6u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdvwrdr933n8yd3xihj6u.png" alt=" " width="758" height="514"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As you can see, there is a '?' column. This signifies that we combined the tables, but the SQL engine couldn't determine a name for it, hence the default '?column?' in the SQL column.&lt;/p&gt;

&lt;p&gt;This one is the revise version &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawygi0upay9z6yxn526g.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fawygi0upay9z6yxn526g.png" alt=" " width="764" height="515"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;We add an alias to the combined column name so that it can be given a column name. This is just one example of how aliases are used. We use aliases in table names, subqueries, etc., as I mentioned earlier. However, we're not discussing those uses now because we're focusing on the basics. We may explore those topics later, but it's important to grasp the fundamentals first.&lt;/p&gt;

&lt;p&gt;Now that you know what is alias is try to apply it in your query and see the improvement. I hope you learn from this blog , Thank you so much again and good day.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;The data that I'm using here is just dummy data sourced from DataCamp, so there's no need to worry, guys.
&lt;em&gt;MARKME&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>postgres</category>
    </item>
    <item>
      <title>SQL DATA TYPES</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Thu, 02 May 2024 13:16:26 +0000</pubDate>
      <link>https://dev.to/marklouisalter/sql-data-types-52a1</link>
      <guid>https://dev.to/marklouisalter/sql-data-types-52a1</guid>
      <description>&lt;p&gt;&lt;strong&gt;Hello Everyone&lt;/strong&gt;, &lt;/p&gt;

&lt;p&gt;This is my &lt;strong&gt;Day 3&lt;/strong&gt; talking about SQL haha if you haven't read my other blogs you can view it in my profile then please read it also and dont forget to like it.&lt;/p&gt;

&lt;p&gt;Now let's go back to our topic for today which is &lt;strong&gt;SQL DATA TYPES&lt;/strong&gt; if you saw my previous post we discuss about queries and some theory about SQL now we're going to focus on sql data types. so first let's define what is data types.&lt;/p&gt;

&lt;p&gt;SQL data types define the type of data that can be stored in the database table's columns. Each column have a data type, which determines the kind of values that can be inserted into that column. It's like were telling each column what only data we are accepting or to store in it.&lt;/p&gt;

&lt;p&gt;Now that we have a glimpse of what is sql data types is now let's discuss the different types of data types.&lt;/p&gt;

&lt;h2&gt;
  
  
  NUMERIC TYPES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;INTEGER/INT&lt;/strong&gt; - Represents integer number whole numbers only no decimal points. there are range that integer are accepting it's like  &lt;strong&gt;-2,147,483,648 to 2,147,483,64&lt;/strong&gt;7 number only. if you want to store big numbers you need  to use &lt;em&gt;BIGINT&lt;/em&gt;. if small numbers &lt;em&gt;SMALLINT&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DECIMAL(n, p)&lt;/strong&gt; - Represents fixed-points numbers with exact precision so if you're data have decimal you need to use decimal types to get also the decimal points of the data. if you use integer type the decimal point will not show.&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  CHARACTER STRING TYPES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt; &lt;strong&gt;CHAR:&lt;/strong&gt; Fixed-length character strings like if you declare your column type is char(5) it will only limit it accepting 5 characters only. &lt;em&gt;CHAR&lt;/em&gt; can be useful when you know that the length of the data will always be the same, as it can help save storage space and ensure consistent data length. &lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;VARCHAR:&lt;/strong&gt; Variable-length character strings. this type is good to store texts the maximum length of this varchar is 255 only.&lt;/li&gt;
&lt;/ul&gt;




&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;TEXT:&lt;/strong&gt;  Variable-length character strings with larger maximum length. this text is same in varchar but the text type can occupy more length than varchar.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  DATE AND TIME TYPES
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;DATE: Represents date values in the format 'YYYY-MM-DD'. Specifically for date only.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;TIME: Represents time values in the format 'HH:MM:SS'. Opposite of the date.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;DATETIME/TIMESTAMP: Represents date and time values in the format 'YYYY-MM-DD HH:MM:SS'. It's like combination of the two above.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h2&gt;
  
  
  Boolean Type:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;BOOLEAN/BOOL: Represents boolean values (true/false).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There are some types commonly found when viewing a database table schema. If you want to dive deeper into the data types, you can find more information in the documentation of your chosen database server, whether it's MySQL or PostgreSQL.&lt;/p&gt;

&lt;p&gt;If you find this blog useful please drop a like and if you have something like concern or feedback you can free to comment on this post and we can discuss it. Thank you so much :) &lt;/p&gt;

&lt;p&gt;&lt;em&gt;MARKME&lt;/em&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>SQL AGGREGATE FUNCTIONS</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Wed, 01 May 2024 12:45:36 +0000</pubDate>
      <link>https://dev.to/marklouisalter/sql-aggregate-functions-5g3d</link>
      <guid>https://dev.to/marklouisalter/sql-aggregate-functions-5g3d</guid>
      <description>&lt;p&gt;&lt;strong&gt;DAY 2&lt;/strong&gt;&lt;br&gt;
Hello Everyone 👋, &lt;/p&gt;

&lt;p&gt;It's me again markme today our topic is aggregate functions in SQL and we're going to walkthrough to some of it such as&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;strong&gt;AVG()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;SUM()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;COUNT()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MIN()&lt;/strong&gt;&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;MAX()&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;and then we're going to use that into query after we discuss it one by one, so let's get start.&lt;/p&gt;

&lt;p&gt;## &lt;strong&gt;AVG() FUNCTION&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;AVG() or average function is getting the average of all records in a selected column.take note that avg fuction is only accepting numbers not string and varchar.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then this is how you use AVG() in a query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT AVG(salary) FROM users&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanation: it will get the average salary of all users in the table that's the output.&lt;/p&gt;




&lt;p&gt;## &lt;strong&gt;SUM() FUNCTION&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;SUM() sum function is used to calculate the sum of values in a column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then this is how you use SUM() in a query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT SUM(salary) FROM users;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanation: In essence, the query fetches the total sum of all salaries stored in the "&lt;em&gt;salary&lt;/em&gt;" column of the "&lt;em&gt;users&lt;/em&gt;".&lt;/p&gt;




&lt;p&gt;## &lt;strong&gt;COUNT() FUNCTION&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;COUNT() count function is used to count the number of rows that meet a specified condition.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then this is how you use COUNT() in a query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT COUNT(salary) FROM users;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanation: In this sample query we're getting the total rows where the salary value is not null or absence. like if there is no value it will not count as 1 it will go to the next row then check the value.&lt;/p&gt;




&lt;p&gt;## &lt;strong&gt;MIN() FUNCTION&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MIN() function is used to retrieve the minimum value from a column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then this is how you use MIN() in a query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT MIN(salary) FROM users;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanation: In this query it will get the minimum value in the salary column it will check all the row who's the lowest value then show it in the output.&lt;/p&gt;




&lt;p&gt;## &lt;strong&gt;MAX() FUNCTION&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MAX() function is used to retrieve the maximum value from a column.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then this is how you use MAX() in a query&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;SELECT MAX(salary) FROM users;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Explanation: In this query it will get the maximum value in the salary column it will check all the row who's the highest value then show it in the output.&lt;/p&gt;

&lt;p&gt;That's the some example of aggregate function when we are going to apply it in sql. its good to use  this aggregate and combine it with group clause.&lt;/p&gt;

&lt;p&gt;Now that you got a glimpse of the aggregate function try to apply that also in your end and explore much more deeper.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;"Consistency is the key to mastery."&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;If you guys have comments or concern about this topic please comment down below. Thanks for reading.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;MARKME&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>mysql</category>
      <category>postgres</category>
    </item>
    <item>
      <title>INTRODUCTION TO SQL</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Tue, 30 Apr 2024 13:07:25 +0000</pubDate>
      <link>https://dev.to/marklouisalter/introduction-to-sql-426c</link>
      <guid>https://dev.to/marklouisalter/introduction-to-sql-426c</guid>
      <description>&lt;p&gt;Hello there 👋 ,&lt;/p&gt;

&lt;p&gt;This is my &lt;strong&gt;DAY 1&lt;/strong&gt; creating blogs about sql and my journey in the world of data field. without further let's get started.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;NOTE: All the topics that im gonna post here is base on what i've understanding and i've learned if you guys thinking that i'm lacking on some explanation in a certain topic feel free to comment down below.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Lesson content for today are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;What is SQL&lt;/li&gt;
&lt;li&gt;SQL Coding Standards and Best Practices&lt;/li&gt;
&lt;li&gt;Order of Execution of SQL&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now let's go with  the first one.&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;WHAT IS SQL&lt;/strong&gt;&lt;br&gt;
SQL is a Structured Query Language. It's a programming language designed for manipulating relational database. So its totally different on NOSQL. it's also allow users to interact with databases by performing various operation such as retrieving data, save, edit, delete, in other term CRUD. &lt;/p&gt;

&lt;p&gt;It's also good choice to choose this language when you are working with data role and you want to manipulate the data.&lt;/p&gt;

&lt;p&gt;The SQL have many flavors or version but we are gonna discuss that in the other day.&lt;/p&gt;

&lt;p&gt;Now that we know what is sql let's make an example how to write an sql.&lt;/p&gt;



&lt;p&gt;&lt;em&gt;Example&lt;/em&gt;&lt;br&gt;
&lt;code&gt;SELECT column_name FROM table_name&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;That's the example query of SQL&lt;br&gt;
&lt;strong&gt;column_name&lt;/strong&gt;: in this part where we gonna put the column name of the table that we want to select.&lt;br&gt;
&lt;strong&gt;table_name&lt;/strong&gt;: in this part is where we gonna call what's the table name we want to query. &lt;/p&gt;

&lt;p&gt;It's like&lt;br&gt;
&lt;code&gt;SELECT id, name FROM Product&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;if you want to put more than 1 column name you need to put comma after the table name that you want to select.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that we are good to go and have some background knowledge what is sql. Were gonna discuss now the SQL Coding Standards and Best Practices&lt;/p&gt;



&lt;p&gt;&lt;strong&gt;SQL Coding Standards and Best Practices&lt;/strong&gt;&lt;br&gt;
 Now let's talk about SQL standards And Best Practices &lt;/p&gt;

&lt;p&gt;Here's some best practices and standards&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;*&lt;em&gt;Use consistent indention for readability *&lt;/em&gt;- meaning that we need to use indention when we're creating a SQL query to make more readable not one liner that if the query is long its hard to read it right?.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example without indention&lt;/strong&gt;: &lt;br&gt;
&lt;code&gt;select id, name, address, username, password, grade from user_info   where status = 1;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Example with indention&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select id
       name
       address
       username
       address
       password
       grade 
from user_info
where status = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;As you can see above it's good to use indention to make more the sql query easy to read and understand at glance compare to the first one without proper indention.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Capitalize SQL keywords for clarity&lt;/strong&gt; - meaning that we need to capitalize the sql keywords to make it more clarity that that's a keyword and not a column name or what.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Example without Capitalize keywords&lt;/strong&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;select id
       name
       address
       username
       address
       password
       grade 
from user_info
where status = 1
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Example with Capitalize keywords&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id
       name
       address
       username
       address
       password
       grade 
FROM user_info
WHERE status = 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;See the difference its good to use capitalization with combination of indention to make more the sql query looks readable.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Comments and Documentation&lt;/strong&gt; - add comments in the sql query can make more the query understandable and well documented.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Example&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT id
       name  -- Name of the person
       address
       username
       address
       password
       grade 
FROM user_info
WHERE status = 1;  -- only fetch the user info with status of 1 or active
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;the -- is the comment for the sql language.&lt;/p&gt;

&lt;p&gt;That are the some sample of best practices and standard coding when you are wring an SQL query if you what to know more or explore much deeper than this you can visit it in the SQL documentation.&lt;/p&gt;

&lt;p&gt;Now that we know some of the standard and best practices in writing an sql query lets proceed now in the last topic which is:&lt;/p&gt;




&lt;p&gt;&lt;strong&gt;Order of Execution of SQL&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Order of execution refers to  the sequence in which different part of an SQL query are processed by the database engine. Understanding this sequence can be crucial when writing efficient queries and comprehending how the database processes and returns results.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT age, 
       COUNT(*) AS total_user
FROM user_account
WHERE status = 1
GROUP BY age,
ORDER BY total_user;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;&lt;p&gt;FROM: The query starts by identifying the table "user_account" from which data will be retrieved.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;WHERE: The WHERE clause filters the rows from the "user_account" table where the status is equal to 1.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;GROUP BY: The query then groups the filtered rows by the "age" column. This means that the rows with the same age will be aggregated together.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;SELECT: Next, the SELECT clause is executed to select the "age" column and the count of rows for each age group. The COUNT(*) function calculates the total number of rows in each age group and aliases it as "total_user".&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;ORDER BY: Finally, the result set is sorted based on the "total_user" column in ascending order. This means that age groups with fewer users will appear first, and those with more users will appear later in the result set.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that you know all of this and have a glimpse of it you can more explore it on the documentation and try to apply it in your end. &lt;/p&gt;

&lt;p&gt;If you have feedback or suggestion feel free to comment it below. see you in the next blog. THANKS &lt;/p&gt;

</description>
      <category>sql</category>
      <category>mysql</category>
      <category>postgres</category>
      <category>database</category>
    </item>
    <item>
      <title>SQL DATA MANIPULATION</title>
      <dc:creator>Markme Dev</dc:creator>
      <pubDate>Mon, 29 Apr 2024 07:38:33 +0000</pubDate>
      <link>https://dev.to/marklouisalter/sql-data-manipulation-2e4j</link>
      <guid>https://dev.to/marklouisalter/sql-data-manipulation-2e4j</guid>
      <description>&lt;p&gt;Hi there 👋&lt;/p&gt;

&lt;p&gt;You're wandering what's this all about so first let me enlightened you. i will be creating a blog everyday from Day 1 to Day 100 to share to you guys what i've learned for that day. this journey will focus on data specifically in sql so let's start.&lt;/p&gt;

&lt;p&gt;Topic for today are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;SQL LEFT FUNCTION&lt;/strong&gt; For efficient Data Extraction.&lt;/li&gt;
&lt;li&gt;SUBSTRING or SUBSTR&lt;/li&gt;
&lt;li&gt;trunc function&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So now you're also wandering again that i am not start in the basics of the sql like the background or syntax i jump from the data manipulations so we will go there. This is &lt;strong&gt;Day 0&lt;/strong&gt; its like a cannon episode haha. enough with the chichat let's start.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SQL LEFT FUNCTION&lt;/strong&gt;&lt;br&gt;
left function is extracting character from a column there's a two argument that needed in performing an left function. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;LEFT(column_name, number)&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The first argument &lt;em&gt;column_name&lt;/em&gt; specifies the column from which you want to extract characters.&lt;/p&gt;

&lt;p&gt;The second argument which is &lt;em&gt;number&lt;/em&gt;  determines the number of characters you want to extract from the left side of the specified column's value.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;For Example&lt;/strong&gt;:&lt;br&gt;
We have &lt;em&gt;Product&lt;/em&gt; table &lt;br&gt;
| id | name       | description              |&lt;br&gt;
|----|------------|--------------------------|&lt;br&gt;
| 1  | Product A  | Description of Product A |&lt;br&gt;
| 2  | Product B  | Description of Product B |&lt;br&gt;
| 3  | Product C  | Description of Product C |&lt;/p&gt;

&lt;p&gt;So if we want to limit the output of the description because its too long then we can use LEFT function to limit the characters of the description column. Lets limit the the fetch description in 5 characters only. this is the sample query for that.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;SELECT name, LEFT(description, 5) AS description FROM Product&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;then the output of that is this &lt;br&gt;
| name       | description |&lt;br&gt;
|------------|-------------|&lt;br&gt;
| Product A  | Descr       |&lt;br&gt;
| Product B  | Descr       |&lt;br&gt;
| Product C  | Descr       |&lt;/p&gt;

&lt;p&gt;you see the description value is cut in 5 characters so thats the uses of left function, We also have RIGHT its same as left but right counting element is start in the right value of the column name.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;SUBSTRING() OR SUBSTR()&lt;/strong&gt;&lt;br&gt;
This function is same on the left function but the substring requires 3 argument. &lt;/p&gt;

&lt;p&gt;SUBSTRING(column name, start(n), end(n));&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;column name: Column name or string that you want to extract.&lt;/li&gt;
&lt;li&gt;start(n): The starting position from which you want to begin extracting characters.&lt;/li&gt;
&lt;li&gt;end(n): The length of the substring you want to extract&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It's easy right?&lt;/p&gt;

&lt;p&gt;now let's make a query, Here's the sample &lt;strong&gt;Product&lt;/strong&gt; Table.&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;id&lt;/th&gt;
&lt;th&gt;name&lt;/th&gt;
&lt;th&gt;description&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;1&lt;/td&gt;
&lt;td&gt;Product A&lt;/td&gt;
&lt;td&gt;Description of Product A&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;2&lt;/td&gt;
&lt;td&gt;Product B&lt;/td&gt;
&lt;td&gt;Description of Product B&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;3&lt;/td&gt;
&lt;td&gt;Product C&lt;/td&gt;
&lt;td&gt;Description of Product C&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;code&gt;SELECT name, SUBSTRING(description, 11, 5) AS description FROM Product;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;THE &lt;strong&gt;OUTPUT&lt;/strong&gt;:&lt;br&gt;
| name       | description  |&lt;br&gt;
|------------|------------- |&lt;br&gt;
| Product A  |  of Pr       |&lt;br&gt;
| Product B  |  of Pr       |&lt;br&gt;
| Product C  |  of Pr       |&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;:&lt;br&gt;
We start the extraction in the 11 char of the description column then the length of the extraction is 5 so we count five starting from element char we also &lt;strong&gt;included the spaces&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;TRUNC()&lt;/strong&gt;&lt;br&gt;
The &lt;em&gt;TRUNC()&lt;/em&gt; function is used to truncate a date or a number to specific unit or measure. its something similar for ROUND but the ROUND is rounding a number in TRUNC we're just eliminating the number or decimal. &lt;/p&gt;

&lt;p&gt;TRUNC function accept two arguments first is the column name containing number or dates, but the second argument is like optional so we can exclude or includes that its depends on the situation. &lt;/p&gt;

&lt;p&gt;Sample query&lt;br&gt;
This is the 3 different example of trunc() function &lt;/p&gt;

&lt;p&gt;TRUNC(salary) -- removing the decimal for salary column&lt;br&gt;
ex: 123.00 -&amp;gt; 123&lt;/p&gt;

&lt;p&gt;TRUNC(salary, 2) -- 123.18730 -&amp;gt; 100.18700&lt;/p&gt;

&lt;p&gt;TRUNC(salary, -2) -- 123.18730 -&amp;gt; 100.00000&lt;/p&gt;

&lt;p&gt;Utilizing the &lt;em&gt;TRUNC()&lt;/em&gt; function to group numbers into specific ranges like thousands or hundreds can greatly facilitate data analysis and interpretation.&lt;/p&gt;

&lt;p&gt;Nice, now that you learned how to use the LEFT(), SUBSTRING(), TRUNC try to apply it in your project and explore it a little bit more advance. &lt;/p&gt;

&lt;p&gt;If you guys have questions or clarifications regarding on my blog post please do a comment and share your thoughts about it and then we can discuss it.&lt;/p&gt;

&lt;p&gt;If you enjoy this type of content and would like to join me on my journey of personal growth in SQL, please hit the like button&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Thank you so much and have a nice day! *&lt;/em&gt;&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>mysql</category>
      <category>postgressql</category>
    </item>
  </channel>
</rss>
