<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Cumaali Celik on Medium]]></title>
        <description><![CDATA[Stories by Cumaali Celik on Medium]]></description>
        <link>https://medium.com/@cumaalicelik?source=rss-1213244ba270------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*ndHcLJ0dUgOBjFDnrkwFBg.jpeg</url>
            <title>Stories by Cumaali Celik on Medium</title>
            <link>https://medium.com/@cumaalicelik?source=rss-1213244ba270------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 00:12:59 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@cumaalicelik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Category Ratios in DAX: A Smarter Approach]]></title>
            <link>https://medium.com/@cumaalicelik/category-ratios-in-dax-a-smarter-approach-9d4d818a0fbd?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/9d4d818a0fbd</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Tue, 04 Feb 2025 15:40:21 GMT</pubDate>
            <atom:updated>2025-02-04T15:40:21.476Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/532/1*reX2GnhLY6fL-6ynpWpegA.png" /></figure><p>DAX is a powerful tool for data analysis, but complexity can make it difficult to understand, debug, and optimize. In this article, we’ll explore two <strong>category ratio</strong> measures — one comparing a category to others and another normalizing it against all categories. Using <strong>variables and a structured approach</strong>, we can write simple, more efficient DAX codes.</p><h4><strong>Category Ratio Measure </strong>(Comparing to Other Categories)</h4><p><strong>DAX Code:</strong></p><pre>Category Ratio =  <br>VAR _CurrentCategory = SELECTEDVALUE(Categories[Category])  <br>VAR _OtherCategories = FILTER(  <br>    ALLSELECTED(Categories[Category]),  <br>    Categories[Category] &lt;&gt; _CurrentCategory  <br>)  <br>VAR _AvgOtherCategorySales = AVERAGEX(_OtherCategories, [Sales])  <br><br>RETURN  <br>IF(  <br>    HASONEVALUE(Categories[Category]),  <br>    DIVIDE([Sales], _AvgOtherCategorySales)  <br>)</pre><h3>How It Works</h3><ol><li><strong>Identify the selected category</strong> → _CurrentCategory stores the currently selected category.</li><li><strong>Filter out this category</strong> → _OtherCategories contains all categories except the selected one.</li><li><strong>Calculate their average sales</strong> → _AvgOtherCategorySales determines the benchmark.</li><li><strong>Compare the selected category</strong> → We divide its sales by the computed average.</li><li>I used here and the below DAX code<strong>HASONEVALUE to avoid incorrect totals</strong> → Ensures calculations only happen when a single category is selected. As you may see the Category Rate column’s total is <strong>BLANK</strong>!</li></ol><h3>Example Output</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f5PW6rV2QcRDpgAKWkelyw.png" /></figure><h4>Normalized Category Ratio Measure</h4><p>DAX Code:</p><pre>Normalized Category Ratio =  <br>VAR _SelectedCategories = ALLSELECTED(Categories[Category])  <br>VAR _AvgSelectedCategorySales = AVERAGEX(_SelectedCategories, [Sales])  <br><br>RETURN  <br>IF(  <br>    HASONEVALUE(Categories[Category]),  <br>    DIVIDE([Sales], _AvgSelectedCategorySales)  <br>)</pre><h3>How It Works</h3><ol><li><strong>Include all selected categories</strong> → _SelectedCategories holds the full dataset.</li><li><strong>Calculate the total average</strong> → _AvgSelectedCategorySales sets a benchmark.</li><li><strong>Compare each category to the overall trend</strong> → We divide its sales by this benchmark.</li></ol><h3>Example Output</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*dICx281cd-vx4vf82UtlFg.png" /></figure><p>Writing <strong>clear, efficient DAX</strong> is crucial for performance and maintainability. By using <strong>variables</strong>, we:</p><p>✅ Make code easier to read and debug<br>✅ Avoid redundant calculations, improving efficiency<br>✅ Ensure flexibility when modifying logic</p><p>Both category ratio measures provide <strong>valuable insights</strong> depending on your use case. Whether you need to <strong>compare a category to others</strong> or <strong>benchmark it against all selections</strong>, these measures simplify analysis.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9d4d818a0fbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ROLLUP in SQL: A Practical Guide with Real-Life Examples]]></title>
            <link>https://medium.com/@cumaalicelik/rollup-in-sql-a-practical-guide-with-real-life-examples-b8915afc307a?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/b8915afc307a</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Wed, 28 Aug 2024 08:48:02 GMT</pubDate>
            <atom:updated>2024-08-28T08:48:02.777Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/337/1*5920Y1QpyXpNKphpMGROiQ.png" /></figure><p>When working with SQL, summarizing data at multiple levels is often necessary, especially when dealing with complex reports or detailed data analysis. The <strong>ROLLUP</strong> operator is a powerful tool that allows you to generate subtotals and grand totals with just one query. In this article, I’ll explain how <strong>ROLLUP</strong> works and share some real-life examples to show how it can be used effectively.</p><h4>What is ROLLUP?</h4><p><strong>ROLLUP</strong> is an extension of the <strong>GROUP BY</strong> clause in SQL. It lets you calculate subtotals for each level of your grouping and a grand total in a single query. This is particularly useful when you need reports that show detailed data breakdowns, along with summarized totals at various levels.</p><h4>How Does ROLLUP Work?</h4><p>When you use <strong>ROLLUP</strong>, SQL first groups your data by all the specified columns, just like a standard <strong>GROUP BY</strong>. Then, it generates subtotals by progressively removing columns from the right, eventually calculating a grand total.</p><p>For instance, with <strong>ROLLUP (column1, column2)</strong>, SQL will:</p><ol><li>Group your data by both <strong>column1</strong> and <strong>column2</strong>.</li><li>Create a subtotal for <strong>column1</strong>.</li><li>Provide a grand total that includes all data.</li></ol><h4>Real-Life Example 1: Product Sales by Category and Month</h4><p>Let’s say you work for a retail company, and you need to generate a report showing monthly sales for each product category. You also want subtotals for each category and a grand total for all sales.</p><p><strong>Table Structure</strong>:</p><ul><li><strong>sales_data</strong>: This table includes <strong>month</strong>, <strong>category</strong>, and <strong>sales_amount</strong>.</li></ul><pre>SELECT month, category, SUM(sales_amount) AS total_sales<br>FROM sales_data<br>GROUP BY ROLLUP (month, category);</pre><p><strong>What It Does</strong>:</p><ul><li>This query gives you the total sales for each category within each month.</li><li>It also provides subtotals for each month and a grand total for all months combined.</li></ul><p><strong>Sample Output</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/716/1*FZUkuEDG1M5ZnHttIQbmgg.png" /></figure><p>Here, the <strong>NULL </strong>values represent the aggregated totals. The subtotal rows show the sum of sales for each category within the month, and the grand total row sums up all sales.</p><h4>Real-Life Example 2: Customer Support Tickets by Priority and Agent</h4><p>Let’s say you’re managing a customer support team, and you need to report on the number of support tickets handled by each agent, broken down by priority level. You also want to see subtotals for each priority level and a grand total of all tickets.</p><p><strong>Table Structure</strong>:</p><ul><li><strong>support_tickets</strong>: This table includes <strong>priority</strong>, <strong>agent</strong>, and <strong>ticket_count</strong>.</li></ul><pre>SELECT priority, agent, SUM(ticket_count) AS total_tickets<br>FROM support_tickets<br>GROUP BY ROLLUP (priority, agent);</pre><p><strong>What It Does</strong>:</p><ul><li>The query calculates the total number of tickets handled by each agent for each priority level.</li><li>It provides subtotals for each priority and a grand total for all tickets.</li></ul><p><strong>Sample Output</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/715/1*Ov_rlv5SrZtdER7tPMhtqQ.png" /></figure><p>This report helps you understand the workload distribution among agents, with clear visibility into how many tickets are being handled at each priority level.</p><h4>Why Use ROLLUP?</h4><ul><li><strong>Efficiency</strong>: <strong>ROLLUP</strong> allows you to get detailed and summary data in one query, saving time and simplifying your reporting process.</li><li><strong>Clarity</strong>: It provides a clear, hierarchical view of your data, making it easier to see the bigger picture and the details simultaneously.</li><li><strong>Versatility</strong>: Whether you’re working in sales, HR, customer support, or any other field, <strong>ROLLUP </strong>can help you create more insightful reports.</li></ul><h4>Conclusion</h4><p>The <strong>ROLLUP </strong>operator is a powerful SQL tool for generating hierarchical summaries. Whether you’re analyzing sales data, tracking employee performance, or managing customer support, <strong>ROLLUP </strong>can help you efficiently summarize your data at multiple levels. By mastering <strong>ROLLUP</strong>, you can create more comprehensive and informative reports, making it easier to understand and communicate your data insights.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b8915afc307a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL User-Defined Functions (UDFs)-2]]></title>
            <link>https://medium.com/@cumaalicelik/sql-user-defined-functions-udfs-2-1cd6dd998394?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/1cd6dd998394</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Sun, 24 Mar 2024 13:27:28 GMT</pubDate>
            <atom:updated>2024-03-24T13:27:28.484Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/603/1*webAyJLxUocLHRtOyA07Dw.png" /></figure><p>In the latest article, we have mentioned some UDFs in SQL. Now we will be examining different usages and examples of them.</p><p><strong>Inline Table-Valued Functions:</strong></p><p>Inline Table-Valued Functions are similar to regular table-valued functions but are defined using the RETURNS TABLE clause inline. They offer better performance compared to multi-statement table-valued functions.</p><p>Example:</p><pre>CREATE FUNCTION dbo.GetHighPerformingEmployees (@threshold INT)<br>RETURNS TABLE<br>AS<br>RETURN<br>(<br>    SELECT * FROM employees WHERE performance_rating &gt;= @threshold<br>);</pre><p>Output:</p><pre>SELECT * FROM dbo.GetHighPerformingEmployees(8);</pre><p><strong>Multi-Statement Table-Valued Functions:</strong></p><p>Multi-Statement Table-Valued Functions allow for more complex logic than inline table-valued functions. They use a BEGIN...END block to define the function body.</p><p>Example:</p><pre>CREATE FUNCTION dbo.GetEmployeesInAgeGroup (@min_age INT, @max_age INT)<br>RETURNS @result TABLE<br>(<br>    employee_id INT,<br>    first_name VARCHAR(50),<br>    last_name VARCHAR(50),<br>    age INT<br>)<br>AS<br>BEGIN<br>    INSERT INTO @result<br>    SELECT employee_id, first_name, last_name, DATEDIFF(YEAR, birthdate, GETDATE()) AS age<br>    FROM employees<br>    WHERE DATEDIFF(YEAR, birthdate, GETDATE()) BETWEEN @min_age AND @max_age;<br><br>    RETURN;<br>END;</pre><p>Output:</p><pre>SELECT * FROM dbo.GetEmployeesInAgeGroup(25, 35);</pre><p><strong>Scalar UDFs with Aggregates:</strong></p><p>Scalar UDFs can also be used in combination with aggregate functions to perform calculations on grouped data.</p><p>Example:</p><pre>CREATE FUNCTION dbo.CalculateAverageSalaryByDepartment (@department_name VARCHAR(50))<br>RETURNS DECIMAL(10, 2)<br>AS<br>BEGIN<br>    DECLARE @avg_salary DECIMAL(10, 2);<br><br>    SELECT @avg_salary = AVG(salary)<br>    FROM employees<br>    WHERE department = @department_name;<br><br>    RETURN @avg_salary;<br>END;</pre><p>Output:</p><pre>SELECT dbo.CalculateAverageSalaryByDepartment(&#39;Engineering&#39;);</pre><p><strong>Recursive UDFs:</strong></p><p>Recursive UDFs are used to solve problems that can be expressed recursively. They call themselves repeatedly until a base condition is met.</p><p>Example:</p><pre>CREATE FUNCTION dbo.CalculateFactorial (@n INT)<br>RETURNS INT<br>AS<br>BEGIN<br>    IF @n &lt;= 1<br>        RETURN 1;<br>    ELSE<br>        RETURN @n * dbo.CalculateFactorial(@n - 1);<br>END;</pre><p>Output:</p><pre>SELECT dbo.CalculateFactorial(5);</pre><p>By incorporating these advanced examples of UDFs into your SQL Server projects, you can leverage their flexibility and power to handle a wide range of data processing tasks efficiently. Remember to consider performance implications and adhere to best practices for optimal results.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1cd6dd998394" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL User-Defined Functions (UDFs)-1]]></title>
            <link>https://medium.com/@cumaalicelik/sql-user-defined-functions-udfs-1-e58fede1e5e3?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/e58fede1e5e3</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Sun, 18 Feb 2024 20:58:29 GMT</pubDate>
            <atom:updated>2024-02-18T20:58:29.871Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XmmcQrjga3TP_KTNNCCvOQ.png" /></figure><p>User-Defined Functions (UDFs) in SQL Server enable developers to encapsulate custom logic for reuse within SQL queries. Let’s start by creating a simple scalar UDF that calculates the square of a number:</p><pre>CREATE FUNCTION dbo.Square (@number INT)<br>RETURNS INT<br>AS<br>BEGIN<br>    RETURN @number * @number;<br>END;</pre><p>Output:</p><pre>SELECT dbo.Square(5); -- Output: 25</pre><p>Types of SQL Server UDFs: <br>1. Scalar Functions Scalar functions return a single value based on input parameters. Let’s create a scalar UDF that concatenates first and last names:</p><pre>CREATE FUNCTION dbo.FullName (@first_name VARCHAR(50), @last_name VARCHAR(50))<br>RETURNS VARCHAR(101)<br>AS<br>BEGIN<br>    RETURN @first_name + &#39; &#39; + @last_name;<br>END;</pre><p>Output:</p><pre>SELECT dbo.FullName(&#39;John&#39;, &#39;Doe&#39;); -- Output: John Doe</pre><p>2. Table-Valued Functions Table-valued functions return a table as the result. Let’s create a table-valued UDF that returns all employees in a given department:</p><pre>CREATE FUNCTION dbo.GetEmployeesInDepartment (@department_name VARCHAR(50))<br>RETURNS TABLE<br>AS<br>RETURN<br>(<br>    SELECT * FROM employees WHERE department = @department_name<br>);</pre><p>Output:</p><pre>SELECT * FROM dbo.GetEmployeesInDepartment(&#39;Sales&#39;);</pre><p>Best Practices and Performance Considerations</p><p>Avoiding Complex Logic Complex logic within UDFs can degrade performance. Let’s create a scalar UDF with simple logic to calculate the square root of a number:</p><pre>CREATE FUNCTION dbo.Sqrt (@number FLOAT)<br>RETURNS FLOAT<br>AS<br>BEGIN<br>    RETURN SQRT(@number);<br>END;</pre><p>Output:</p><pre>SELECT dbo.Sqrt(25); -- Output: 5.0</pre><p>Proper Indexing for Table-Valued Functions</p><p>Proper indexing on tables used within table-valued functions can enhance performance. Let’s ensure an index exists on the ‘department’ column in the ‘employees’ table for the previous table-valued function to perform optimally.</p><pre>CREATE INDEX idx_department ON employees(department);</pre><p>Conclusion: SQL Server User-Defined Functions offer a powerful mechanism for encapsulating custom logic within SQL queries, enhancing code reusability and maintainability. By understanding the different types of UDFs, adhering to best practices, and considering performance implications, developers can leverage UDFs effectively to streamline database development and improve overall system efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e58fede1e5e3" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[SQL String Functions]]></title>
            <link>https://medium.com/@cumaalicelik/sql-string-functions-348b7f379429?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/348b7f379429</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Sun, 17 Dec 2023 11:42:47 GMT</pubDate>
            <atom:updated>2023-12-17T11:42:47.980Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*ZhC9iJ0KOwoviGxQiMhXXw.png" /></figure><p>Structured Query Language (SQL) offers a rich set of string functions that empower database professionals to manipulate and analyze text data effectively. In this guide, we’ll explore diverse scenarios and real-life examples to demonstrate the power of various SQL string functions.</p><h3>1. CONCAT() — Concatenate Strings</h3><p>Consider a ‘products’ table with ‘brand’ and ‘model’ columns. You want to create a list of product names by concatenating the brand and model:</p><pre>SELECT brand, model, CONCAT(brand, &#39; &#39;, model) AS product_name<br>FROM products;</pre><p>Output:</p><p>Brand | Model | Product_name</p><ul><li>Samsung | Galaxy | Samsung Galaxy</li><li>Apple | iPhone | Apple iPhone</li><li>Sony | Xperia | Sony Xperia</li></ul><h3>2. SUBSTRING() — Extract Substrings</h3><p>Suppose you have a ‘blog_posts’ table with a ‘content’ column, and you want to display a brief snippet of the content for a blog preview. I have penned an article about this topic in detail, kindly check <a href="https://medium.com/@cumaalicelik/mastering-substring-method-in-sql-6840e6c36a38"><strong>my previous writing</strong></a>:</p><pre>SELECT title, content, SUBSTRING(content, 1, 100) AS preview_content<br>FROM blog_posts;</pre><p>Output:</p><p>Title | Content | Preview_content</p><ul><li>“Introduction to SQL” | “SQL is a powerful query language…” | “SQL is a powerful…”</li><li>“Data Visualization” | “Exploring creative ways to visualize…” | “Exploring creative…”</li><li>“Web Development” | “Building dynamic and interactive websites…” | “Building dynamic…”</li></ul><h3>3. REPLACE() — Replace Substrings</h3><p>Imagine a ‘comments’ table where users might include email addresses, and you want to mask them for privacy:</p><pre>SELECT comment, REPLACE(comment, &#39;@&#39;, &#39;[at]&#39;) AS masked_comment<br>FROM user_comments;</pre><p>Output:</p><p>Comment | Masked_comment</p><ul><li>“Great article! <a href="/service/mailto:user@example.com">user@example.com</a>” | “Great article! user[at]example.com”</li><li>“I disagree with your point of view.” | “I disagree with your point of view.”</li><li>“Contact me: <a href="/service/mailto:info@website.com">info@website.com</a>” | “Contact me: info[at]website.com”</li></ul><h3>4. CHARINDEX() — Find Substring Position</h3><p>Suppose you have a ‘file_paths’ table, and you want to extract the file extensions:</p><pre>SELECT file_path,<br> CHARINDEX(&#39;.&#39;, REVERSE(file_path)) AS last_dot_position,<br> RIGHT(file_path, CHARINDEX(&#39;.&#39;, REVERSE(file_path)) - 1) AS file_extension<br>FROM file_paths;</pre><p>Output:</p><p>File_path | Last_dot_position | File_extension</p><ul><li>“/documents/file.docx” | 4 | “docx”</li><li>“/images/picture.jpg” | 4 | “jpg”</li><li>“/videos/movie.mp4” | 4 | “mp4”</li></ul><h3>5. UPPER() and LOWER() — Convert Case</h3><p>Imagine a ‘usernames’ table, and you want to standardize the username format by converting all usernames to lowercase:</p><pre>SELECT username, LOWER(username) AS standardized_username<br>FROM usernames;</pre><p>Output:</p><p>Username | Standardized_username</p><ul><li>“JohnDoe” | “johndoe”</li><li>“Alice123” | “alice123”</li><li>“TechGuru” | “techguru”</li></ul><h3>6. LEN() or LENGTH() — Get String Length</h3><p>Consider a ‘messages’ table with a ‘content’ column, and you want to retrieve the length of each message:</p><pre>SELECT content, LEN(content) AS message_length<br>FROM messages;</pre><p>Output:</p><p>Content | Message_length</p><ul><li>“Hello, how are you?” | 19</li><li>“Meeting at 2 PM tomorrow!” | 25</li><li>“SQL is fun!” | 12</li></ul><h3>7. LEFT() and RIGHT() — Extract Characters from the Start or End</h3><p>Suppose you have a ‘file_names’ table, and you want to extract the first and last three characters of each file name:</p><pre>SELECT file_name,<br>       LEFT(file_name, 3) AS beginning_chars,<br>       RIGHT(file_name, 3) AS ending_chars<br>FROM file_names;</pre><p>Output:</p><p>File_name | Beginning_chars | Ending_chars</p><ul><li>“document1.docx” | “doc” | “ocx”</li><li>“image123.jpg” | “ima” | “jpg”</li><li>“video_xyz.mp4” | “vid” | “mp4”</li></ul><h3>8. LTRIM() and RTRIM() — Remove Leading and Trailing Spaces</h3><p>Assume you have an ‘institution_names’ table with school names that might have extra spaces, and you want to clean them:</p><pre>SELECT institution_name, LTRIM(RTRIM(institution_name)) AS cleaned_name<br>FROM institution_names;</pre><p>Output:</p><p>Institution_name | Cleaned_name</p><ul><li>“ School Name “ | “School Name”</li><li>“College Name “ | “College Name”</li><li>“ University XYZ “ | “University XYZ”</li></ul><p>These examples showcase the versatility of various SQL string functions, providing practical solutions for manipulating and analyzing textual data in diverse real-world scenarios. Whether you’re concatenating strings, extracting substrings, or cleaning up data, SQL string functions are powerful tools in your database toolkit.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=348b7f379429" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Handling with NULL Values in SQL]]></title>
            <link>https://medium.com/@cumaalicelik/handling-with-null-values-in-sql-77a0e4237d6b?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/77a0e4237d6b</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Sun, 26 Nov 2023 13:40:08 GMT</pubDate>
            <atom:updated>2023-11-26T13:40:41.289Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/511/1*UGtNR5nf8Zn_As_qRwRNeg.png" /></figure><p>In SQL, efficiently handling NULL values is a critical aspect of database query construction. This guide delves into the <strong>ISNULL()</strong> and <strong>COALESCE()</strong> functions, showcasing their syntax, practical examples, and how they contribute to managing NULLs in SQL.</p><p>In SQL, <strong>NULL </strong>represents the absence of a value in a column. Handling NULLs is crucial for accurate and reliable data processing.</p><p><strong>The ISNULL() Function</strong></p><p>Syntax:</p><pre>ISNULL(expression, replacement_value)</pre><p>The <strong>ISNULL</strong>() function is used to replace NULL values with a specified replacement value.</p><p><strong>Example 1</strong>:</p><p>Consider a scenario where you have a table employees with an id column. You want to retrieve the id where a specific condition is met. If the result is NULL, replace it with a default value.</p><pre>SELECT employee_id, <br>       job_title, <br>       ISNULL((SELECT manager_id <br>               FROM managers <br>               WHERE managers.employee_id = employees.employee_id), &#39;No Manager&#39;) AS replaced_manager<br>FROM employees;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*4V2vXsgJwnwuQOLKzBX73A.png" /></figure><p><strong>Example 2:</strong></p><pre>SELECT employee_id, <br>       job_title, <br>       ISNULL(salary, 0) AS replaced_salary<br>FROM employees;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*6eWmJlaexV91qB1iaGEDgA.png" /></figure><p><strong>The COALESCE() Function</strong></p><p>Syntax:</p><pre>COALESCE(expression1, expression2, ..., expressionN)</pre><p>The <strong>COALESCE</strong>() function returns the first non-NULL expression in the list.</p><p><strong>Example 3:</strong></p><p>Building on the previous scenario, let’s use COALESCE() to achieve the same result.</p><pre>SELECT employee_id, <br>       job_title, <br>       COALESCE((SELECT manager_id <br>                 FROM managers <br>                 WHERE managers.employee_id = employees.employee_id), &#39;No Manager&#39;) AS replaced_manager<br>FROM employees;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*4V2vXsgJwnwuQOLKzBX73A.png" /></figure><p><strong>Handling Multiple Columns with COALESCE()</strong></p><p>Unlike <strong>ISNULL</strong>(), using <strong>COALESCE()</strong> can handle NULL values in multiple columns.</p><pre>SELECT employee_id, <br>       COALESCE(first_name, &#39;Unknown&#39;) AS first_name,<br>       COALESCE(last_name, &#39;Unknown&#39;) AS last_name,<br>       COALESCE(salary, 0) AS salary<br>FROM employees;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*GBrdhzCJ9iCwHASPU7AFFA.png" /></figure><p><strong>Handling Division by NULL:</strong></p><pre>SELECT column1 / COALESCE(column2, 1) AS result<br>FROM your_table;</pre><p>In this example, division by NULL is avoided by replacing NULL with 1.</p><p><strong>Using NULLIF():</strong></p><p>The <strong>NULLIF()</strong> function can be handy when you want to return NULL if two expressions are equal.</p><pre>SELECT NULLIF(column1, column2) AS result<br>FROM your_table;</pre><p>If column1 and column2 are equal, the result will be NULL.</p><h3>Conclusion</h3><p>Effectively managing NULL values is an essential skill for SQL developers. <strong>ISNULL()</strong> and <strong>COALESCE()</strong> are powerful tools in this regard, providing flexibility and precision in handling NULL scenarios. As you navigate through complex queries and real-world database interactions, incorporating these functions into your toolkit enhances the robustness and reliability of your SQL statements.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=77a0e4237d6b" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Exploring SQL Date Functions]]></title>
            <link>https://medium.com/@cumaalicelik/exploring-sql-date-functions-648a588c6e5a?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/648a588c6e5a</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Thu, 28 Sep 2023 08:05:24 GMT</pubDate>
            <atom:updated>2023-09-28T08:05:24.830Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*mzRU-pFmiTxHfodzlbmwJQ.jpeg" /><figcaption>SQL Date Functions</figcaption></figure><p>Dates and timestamps form the backbone of database management, seamlessly integrating into a multitude of business contexts. SQL, renowned for its extensive array of date functions, equips data professionals with a formidable toolkit to master the art of managing, manipulating, and extracting profound insights from date-related data. In this all-encompassing guide, we embark on an illuminating journey through the realm of SQL’s date functions. Each function is dissected comprehensively, accompanied by practical examples that vividly showcase their capabilities.</p><p>In this article, we dive deep into SQL’s rich environment of date functions, an essential toolkit for managing and analyzing date-related data. Our journey will include a comprehensive exploration of functions like <strong>GETDATE(), DATEDIFF, DATEADD, FORMAT,</strong> and more. Practical examples with clear outputs will illuminate the path, enabling you to harness the full potential of these functions in your SQL endeavors.</p><h4>GETDATE() — Retrieving Current Date and Time</h4><p>The GETDATE() function is your gateway to real-time data processing in SQL. It returns the current date and time when executed. Let&#39;s consider an example where we want to fetch all orders placed today or later:</p><pre>SELECT <br>    OrderID,<br>    OrderDate<br>FROM <br>    Orders<br>WHERE <br>    OrderDate &gt;= GETDATE();</pre><p>Expected Output:</p><pre>| OrderID | OrderDate  |<br>| ------- | ---------- |<br>| 1       | 2023-09-15 |<br>| 2       | 2023-09-20 |<br>| 3       | 2023-09-25 |</pre><p>In this example, we leverage GETDATE() to dynamically filter orders based on the current date, making it an invaluable tool for real-time data analysis.</p><h4>DATEDIFF() — Calculating Date Differences</h4><p>The DATEDIFF() function measures the interval between two dates in terms of a specified unit (e.g., days, months, years). Let&#39;s calculate the age of customers based on their birthdates:</p><pre>SELECT <br>    CustomerName,<br>    BirthDate,<br>    DATEDIFF(YEAR, BirthDate, GETDATE()) AS AgeInYears<br>FROM <br>    Customers;</pre><p>Expected Output:</p><pre>| CustomerName | BirthDate  | AgeInYears |<br>| ------------ | ---------- | ---------- |<br>| Alice        | 1990-05-15 | 33         |<br>| Bob          | 1985-02-20 | 38         |<br>| Carol        | 1978-11-10 | 44         |</pre><p>In this example, we use DATEDIFF() to accurately calculate the age of customers, accounting for leap years.</p><h4>DATEADD() — Manipulating Dates</h4><p>The DATEADD() function allows you to perform date arithmetic by adding or subtracting intervals from a date. Consider calculating the date one week from an event date:</p><pre>SELECT <br>    EventDate,<br>    DATEADD(WEEK, 1, EventDate) AS OneWeekLater<br>FROM <br>    Events;</pre><p>Expected Output:</p><pre>| EventDate  | OneWeekLater |<br>| ---------- | ------------ |<br>| 2023-01-15 | 2023-01-22   |<br>| 2023-02-20 | 2023-02-27   |<br>| 2023-03-10 | 2023-03-17   |</pre><p>Here, DATEADD() helps us determine the date exactly one week after each event.</p><h4>FORMAT() — Customizing Date Display</h4><p>Formatting dates is essential for making data more user-friendly. The FORMAT() function enables you to display dates in a customized format:</p><pre>SELECT <br>    EventDate,<br>    FORMAT(EventDate, &#39;MMMM dd, yyyy&#39;) AS FormattedDate<br>FROM <br>    Events;</pre><p>Expected Output:</p><pre>| EventDate  | FormattedDate       |<br>| ---------- | -------------------- |<br>| 2023-01-15 | January 15, 2023     |<br>| 2023-02-20 | February 20, 2023    |<br>| 2023-03-10 | March 10, 2023       |</pre><p>In this example, we use FORMAT() to present event dates in a more readable format.</p><pre>SELECT FORMAT(GETDATE(), &#39;MM/dd/yyyy&#39;)</pre><p>This query serves to retrieve the current date and time using the GETDATE() function and then format it according to the specified date format &#39;MM/dd/yyyy.&#39;</p><p>Here, I’ll break down the date format codes within the format string for better understanding:</p><ul><li>yyyy: This code represents the year with the century, providing a four-digit representation (e.g., 2023).</li><li>yy: This code signifies the year without the century, offering a two-digit representation (e.g., 23).</li><li>MM: The &#39;MM&#39; code denotes the month as a two-digit number (e.g., 02 for February).</li><li>MMM: This code corresponds to the abbreviated month name (e.g., Feb).</li><li>MMMM: The &#39;MMMM&#39; code represents the full month name (e.g., February).</li><li>dd: This code stands for the day of the month as a two-digit number (e.g., 03).</li><li>ddd: &#39;ddd&#39; signifies the abbreviated day name (e.g., Tue).</li><li>dddd: Lastly, &#39;dddd&#39; represents the full day name (e.g., Tuesday).</li></ul><h4>DATEPART() — Extracting Date Components</h4><p>The DATEPART() function allows you to extract specific date components, such as day of the week or month. Let&#39;s retrieve the day of the week for each order:</p><pre>SELECT <br>    OrderID,<br>    OrderDate,<br>    DATEPART(WEEKDAY, OrderDate) AS DayOfWeek<br>FROM <br>    Orders;</pre><p>Expected Output:</p><pre>| OrderID | OrderDate  | DayOfWeek |<br>| ------- | ---------- | --------- |<br>| 1       | 2023-01-15 | 1         |<br>| 2       | 2023-02-20 | 2         |<br>| 3       | 2023-03-10 | 6         |</pre><p>Here, we use DATEPART() to identify the day of the week when each order was placed.</p><h4>DATEFROMPARTS() — Creating Dates from Parts</h4><p>The DATEFROMPARTS() function allows you to construct a date from separate year, month, and day components. Suppose you have year, month, and day columns and want to form complete dates:</p><pre>SELECT <br>    YearColumn,<br>    MonthColumn,<br>    DayColumn,<br>    DATEFROMPARTS(YearColumn, MonthColumn, DayColumn) AS FullDate<br>FROM <br>    YourTable;</pre><p>Expected Output:</p><pre>| YearColumn | MonthColumn | DayColumn | FullDate   |<br>| ---------- | ----------- | --------- | ---------- |<br>| 2023       | 5           | 15        | 2023-05-15 |<br>| 2023       | 2           | 20        | 2023-02-20 |<br>| 2023       | 11          | 10        | 2023-11-10 |</pre><p>In this example, DATEFROMPARTS() allows us to create complete dates from individual date components.</p><h4>Using DATE Functions in Combination</h4><p>SQL date functions can be combined to solve more complex problems. Let’s say you want to find all orders placed between two weeks ago and today:</p><pre>SELECT <br>    OrderID,<br>    OrderDate<br>FROM <br>    Orders<br>WHERE <br>    OrderDate BETWEEN DATEADD(WEEK, -2, GETDATE()) AND GETDATE();</pre><p>Expected Output:</p><pre>| OrderID | OrderDate  |<br>| ------- | ---------- |<br>| 1       | 2023-09-15 |<br>| 2       | 2023-09-20 |<br>| 3       | 2023-09-25 |</pre><p>Here, we use GETDATE() and DATEADD() together to retrieve orders within the specified time frame.</p><p>Mastering these functions not only enhances your proficiency in SQL but also equips you with the skills needed to navigate the intricacies of date-related data effortlessly. This proficiency is particularly valuable in today’s data-driven world, where the precision and accuracy of date-related information play a pivotal role in decision-making processes.</p><p>By understanding the practical applications and nuances of SQL date functions, you’re poised to tackle date-related challenges with confidence and finesse. Whether you’re a database administrator, data analyst, or software developer, these skills empower you to manipulate and extract insights from date-related data efficiently, contributing to the success of your projects and the quality of your data analysis. With SQL date functions as part of your skill set, you’re well-prepared to navigate the complexities of managing dates within databases and leverage their power for data-driven decision-making.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=648a588c6e5a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ Unraveling Data Patterns with SQL WHERE Clauses: Filtering Insights]]></title>
            <link>https://medium.com/@cumaalicelik/unraveling-data-patterns-with-sql-where-clauses-filtering-insights-93f392bd67a9?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/93f392bd67a9</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Mon, 21 Aug 2023 09:33:02 GMT</pubDate>
            <atom:updated>2024-03-17T11:24:37.908Z</atom:updated>
            <content:encoded><![CDATA[<h3>Unraveling Data Patterns with SQL WHERE Clauses: Filtering Insights</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*ouVoiytEQPMeIfuhHpVTGA.png" /></figure><p>In the world of databases, data can be vast and overwhelming. The <strong>WHERE </strong>clause in SQL helps us filter and extract precisely the information we need, providing us with more focused and insightful results.</p><p><strong>Scenario 1:</strong></p><p>You’re managing an e-commerce platform, and you want to extract products within a certain price range.</p><p><strong>SQL Code:</strong></p><pre>SELECT product_name, price<br>FROM products<br>WHERE price BETWEEN 20 AND 50;</pre><p><strong>Output:</strong></p><pre>product_name         | price<br>-----------------------------<br>T-Shirt - Summer     | 20.00<br>Sneakers - Classic   | 35.46<br>Phone Case - Neon    | 49.99</pre><p><strong>Scenario 2:</strong></p><p>You’re analyzing customer feedback and want to retrieve reviews containing the word “excellent.”</p><p><strong>SQL Code:</strong></p><pre>SELECT customer_name, review<br>FROM customer_reviews<br>WHERE review LIKE &#39;%excellent%&#39;;</pre><p><strong>Output:</strong></p><pre>customer_name     | review<br>----------------------------<br>Jane Smith        | Excellent service and product quality!<br>Alex Johnson      | I had an excellent experience shopping here.</pre><p><strong>Scenario 3:</strong></p><p>You’re managing an employee database and want to extract employees who are both in the “Sales” department and have a salary greater than $50000.</p><p><strong>SQL Code:</strong></p><pre>SELECT employee_name, department, salary<br>FROM employees<br>WHERE department = &#39;Sales&#39; AND salary &gt; 50000;</pre><p><strong>Output:</strong></p><pre>employee_name   | department | salary<br>-------------------------------------<br>John Anderson   | Sales      | 55000<br>Laura Williams  | Sales      | 60000</pre><p><strong>Scenario 4:</strong></p><p>You’re analyzing customer data and want to retrieve records with missing email addresses.</p><p><strong>SQL Code:</strong></p><pre>SELECT customer_name, email<br>FROM customers<br>WHERE email IS NULL;</pre><p><strong>Output:</strong></p><pre>customer_name   | email<br>-----------------------<br>Michael Brown   | NULL<br>Jennifer Lee    | NULL</pre><p>In summary, SQL’s <strong>WHERE </strong>clauses serve as an invaluable lens through which data can be meticulously examined. They provide the means to refine your database inquiries to specific insights, encompassing tasks such as refining numerical ranges, identifying patterns, and amalgamating conditions.</p><p>Metaphorically speaking, these clauses act as illuminating spotlights that expose concealed narratives within your data. By incorporating <strong>WHERE </strong>clauses into your SQL arsenal, you acquire the capacity for precision in query formulation.</p><p>Regarded as navigational tools, <strong>WHERE </strong>clauses steer you through the intricate terrain of information. They aid in unearthing insights, facilitating informed choices, and navigating your data odyssey with a sense of certainty.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=93f392bd67a9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Commen Aggregate Functions in SQL]]></title>
            <link>https://medium.com/@cumaalicelik/commen-aggregate-functions-in-sql-606e10890d8d?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/606e10890d8d</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Tue, 08 Aug 2023 08:04:01 GMT</pubDate>
            <atom:updated>2023-08-08T08:04:01.593Z</atom:updated>
            <content:encoded><![CDATA[<p>Aggregate functions in <strong>SQL </strong>are specially designed functions that perform calculations on a set of values and return a single value. These functions are commonly used to perform operations like counting, summing, averaging, finding the maximum and minimum values, and more across multiple rows of a table.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*rC3hlifMGJaPgg78meSVTw.jpeg" /></figure><p>Let’s take a closer look at some commonly used aggregate functions:</p><ol><li><strong>COUNT()</strong>: This function returns the number of rows in a specified column or table. It’s often used to count the occurrences of specific data points.</li><li><strong>SUM()</strong>: The SUM() function calculates the total sum of the values in a numeric column. It’s useful for tasks like adding up sales figures or calculating total revenue.</li><li><strong>AVG():</strong> AVG() calculates the average of the values in a numeric column. It’s handy for finding the average score of students or the average price of products.</li><li><strong>MAX()</strong>: MAX() retrieves the maximum value from a column. For instance, it can be used to find the highest temperature recorded in a dataset.</li><li><strong>MIN()</strong>: Conversely, MIN() returns the minimum value from a column. It’s often used to identify the lowest stock price, for example.</li></ol><h3>How to Use Aggregate Functions</h3><p>Aggregate functions are typically used in conjunction with the SELECT statement. Here’s a basic syntax to demonstrate their usage:</p><pre>SELECT aggregate_function(column_name)<br>FROM table_name<br>WHERE conditions;</pre><p>Assuming the “Sales” table looks like this:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/816/1*CAeMmL04HAGjN_D6MDtCOQ.png" /></figure><p><strong>1.COUNT()</strong>: Count the number of records in the table.</p><pre>SELECT COUNT(*)<br>FROM Sales;</pre><p>👉Output: ‘5’</p><p><strong>2.SUM()</strong>: Calculate the total quantity of all products sold.</p><pre>SELECT SUM(Quantity)<br>FROM Sales;</pre><p>👉Output: ‘41’</p><p><strong>3.AVG()</strong>: Calculate the average price of all products.</p><pre>SELECT AVG(Price)<br>FROM Sales;</pre><p>👉Output: ‘16’</p><p><strong>4.MAX()</strong>: Find the maximum price among all products.</p><pre>SELECT MAX(Price)<br>FROM Sales;</pre><p>👉Output: ‘20’</p><p><strong>5.MIN()</strong>: Find the minimum quantity sold among all products.</p><pre>SELECT MIN(Quantity)<br>FROM Sales;</pre><p>👉Output: ‘3’</p><h3>Conclusion</h3><p>Aggregate functions in <strong>SQL </strong>simplify data analysis by providing an easy way to summarize and derive insights from large datasets. Whether you’re counting records, calculating averages, finding maximum or minimum values, or performing other <strong>aggregate </strong>calculations, these functions play a crucial role in generating valuable information. Understanding the basics of aggregate functions is a fundamental step toward becoming proficient in SQL data manipulation.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=606e10890d8d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Uniting Data with SQL Joins]]></title>
            <link>https://medium.com/@cumaalicelik/uniting-data-with-sql-joins-9bfbe4fbb031?source=rss-1213244ba270------2</link>
            <guid isPermaLink="false">https://medium.com/p/9bfbe4fbb031</guid>
            <dc:creator><![CDATA[Cumaali Celik]]></dc:creator>
            <pubDate>Wed, 02 Aug 2023 07:40:16 GMT</pubDate>
            <atom:updated>2023-08-02T07:46:41.162Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/696/1*CrfEjfqXUAVO5__4btQqeg.png" /></figure><blockquote><strong><em>The Basics of SQL Joins</em></strong><em>: SQL joins work by matching data from one table to another based on a common column. For example, if both tables have an “EmployeeID” column, we can use that to bring together details about employees and their salaries.</em></blockquote><p><strong>Employees Table:</strong></p><pre>EmployeeID | EmployeeName<br>-------------------------<br>101        | John<br>102        | Mary<br>103        | Alice</pre><p><strong>Salaries Table:</strong></p><pre>SalaryID | EmployeeID | SalaryAmount<br>------------------------------------<br>201      | 101        | 5000<br>202      | 102        | 6000<br>203      | 103        | 5500</pre><ul><li><strong>Inner Join</strong>: Think of an inner join like a filter that only keeps the rows that match in both tables. It shows us only the employees who have a corresponding salary entry. We get a tidy list with just the information we need, no extras.</li></ul><p>📝 SQL Query for <strong>Inner Join</strong>:</p><pre>SELECT Employees.EmployeeID, Employees.EmployeeName, Salaries.SalaryID, Salaries.SalaryAmount<br>FROM Employees<br>INNER JOIN Salaries<br>ON Employees.EmployeeID = Salaries.EmployeeID;</pre><p>👉 Output for <strong>Inner Join</strong>:</p><pre>EmployeeID | EmployeeName | SalaryID | SalaryAmount<br>--------------------------------------------------<br>101        | John         | 201      | 5000<br>102        | Mary         | 202      | 6000<br>103        | Alice        | 203      | 5500</pre><ul><li><strong>Left Join</strong>: The left join is like a complete list of employees, along with their matching salaries if available. Even if an employee doesn’t have a salary entry yet, they still show up with a “NULL” in the salary column. It’s like everyone gets an invitation to the party, but not everyone brings a gift.</li></ul><p>📝 SQL Query for <strong>Left Join</strong>:</p><pre>SELECT Employees.EmployeeID, Employees.EmployeeName, Salaries.SalaryID, Salaries.SalaryAmount<br>FROM Employees<br>LEFT JOIN Salaries<br>ON Employees.EmployeeID = Salaries.EmployeeID;</pre><p>👉 Output for <strong>Left Join</strong>:</p><pre>EmployeeID | EmployeeName | SalaryID | SalaryAmount<br>--------------------------------------------------<br>101        | John         | 201      | 5000<br>102        | Mary         | 202      | 6000<br>103        | Alice        | 203      | 5500</pre><ul><li><strong>Right Join</strong>: The right join is just like the left join, but it’s the salaries table that takes center stage. We get a list of all salary details, and if an employee is missing from the employee’s table, we still see the salary info with “NULL” in the employee details. Everyone’s welcome, and salaries are the star.</li></ul><p>📝 SQL Query for <strong>Right Join</strong>:</p><pre>SELECT Employees.EmployeeID, Employees.EmployeeName, Salaries.SalaryID, Salaries.SalaryAmount<br>FROM Employees<br>RIGHT JOIN Salaries<br>ON Employees.EmployeeID = Salaries.EmployeeID;</pre><p>👉 Output for <strong>Right Join</strong>:</p><pre>EmployeeID | EmployeeName | SalaryID | SalaryAmount<br>--------------------------------------------------<br>101        | John         | 201      | 5000<br>102        | Mary         | 202      | 6000<br>103        | Alice        | 203      | 5500</pre><ul><li><strong>Full Join</strong>: A full join is the ultimate party! It includes everyone from both tables, no one is left out. If there’s a match, great, we see the info. If not, we still see the data with “<strong>NULL</strong>” where it’s missing. It’s like getting a complete guest list with all the info we have.</li></ul><p>📝 SQL Query for <strong>Full Join</strong>:</p><pre>SELECT Employees.EmployeeID, Employees.EmployeeName, Salaries.SalaryID, Salaries.SalaryAmount<br>FROM Employees<br>FULL JOIN Salaries<br>ON Employees.EmployeeID = Salaries.EmployeeID;</pre><p>👉 Output for <strong>Full Join</strong>:</p><pre>EmployeeID | EmployeeName | SalaryID | SalaryAmount<br>--------------------------------------------------<br>101        | John         | 201      | 5000<br>102        | Mary         | 202      | 6000<br>103        | Alice        | 203      | 5500<br>NULL       | NULL         | 204      | 7000<br>NULL       | NULL         | 205      | 8000</pre><ul><li>*** In this example, there are two additional rows with <strong>NULL </strong>values for EmployeeID and EmployeeName because they exist in the “Salaries” table but not in the “Employees” table.</li></ul><p>Consequently, SQL joins are like magic tools that help us combine data from different tables into meaningful and complete sets. They allow us to create powerful reports, analyze information, and gain valuable insights from our databases. With inner, left, right, and full joins, we can find the right way to unite our data and make it work for us in the most effective way.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=9bfbe4fbb031" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>