<?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>Forem: muriithilydia46-wq</title>
    <description>The latest articles on Forem by muriithilydia46-wq (@muriithilydia46wq).</description>
    <link>https://forem.com/muriithilydia46wq</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%2F3818868%2Fe702bd0c-4bc2-4904-bf18-5b5242cb8e4e.jpg</url>
      <title>Forem: muriithilydia46-wq</title>
      <link>https://forem.com/muriithilydia46wq</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/muriithilydia46wq"/>
    <language>en</language>
    <item>
      <title>The Query Inside the Query: Understanding Subqueries and CTEs in SQL</title>
      <dc:creator>muriithilydia46-wq</dc:creator>
      <pubDate>Tue, 28 Apr 2026 07:02:38 +0000</pubDate>
      <link>https://forem.com/muriithilydia46wq/the-query-inside-the-query-understanding-subqueries-and-ctes-in-sql-19ig</link>
      <guid>https://forem.com/muriithilydia46wq/the-query-inside-the-query-understanding-subqueries-and-ctes-in-sql-19ig</guid>
      <description>&lt;p&gt;Have you ever written an SQL query, looked at it five minutes later, and had absolutely no idea what it was doing? You are not alone. Most SQL beginners hit a wall when their queries start growing. &lt;/p&gt;

&lt;p&gt;In this article, we are going to look at two powerful SQL tools; &lt;strong&gt;subqueries and CTEs.&lt;/strong&gt; We shall understand what they are, when to use them, and why CTEs might just change the way you write SQL forever.&lt;/p&gt;

&lt;h2&gt;
  
  
  Part 1: Subqueries
&lt;/h2&gt;

&lt;p&gt;A subquery is simply a SELECT statement written inside another SELECT statement. The inner query runs first, and its results is handed to the outer query.&lt;/p&gt;

&lt;p&gt;Let us look at an example from city hospital data;&lt;/p&gt;

&lt;p&gt;"Question: Find all patients who paid more than the average appointment fee."&lt;/p&gt;

&lt;p&gt;SELECT patient_id, diagnosis, fee&lt;br&gt;
FROM appointments&lt;br&gt;
WHERE fee &amp;gt; (SELECT AVG(fee) FROM appointments);&lt;/p&gt;

&lt;p&gt;In this case, the inner query (SELECT AVG(fee) FROM appointments) runs first and returns a number. The outer query then uses that number to filter results. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Commonly used types:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Scalar subquery — returns one single value. Used in WHERE or SELECT.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;e.g., What is each student's mark compared to the class average?&lt;/p&gt;

&lt;p&gt;SELECT student_id, marks,&lt;br&gt;
       (SELECT ROUND(AVG(marks),2) FROM exam_results) AS class_avg&lt;br&gt;
FROM exam_results;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;List subquery — returns a column of values. Used with IN or NOT IN.
e.g., Which patients have had at least one appointment?&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SELECT full_name FROM patients&lt;br&gt;
WHERE patient_id IN (SELECT DISTINCT patient_id FROM appointments);&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Table (Derived) — returns a full mini-table. Used with the FROM clause.&lt;br&gt;
e.g., Find departments where the average marks exceed 65&lt;br&gt;
SELECT department, avg_marks&lt;br&gt;
FROM (&lt;br&gt;
SELECT s.department, ROUND(AVG(er.marks), 2) AS avg_marks&lt;br&gt;
FROM exam_results er&lt;br&gt;
JOIN subjects s ON s.subject_id = er.subject_id&lt;br&gt;
GROUP BY s.department&lt;br&gt;
) AS dept_summary&lt;br&gt;
WHERE avg_marks &amp;gt; 65;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Correlated — references the outer query. It runs once per row.&lt;br&gt;
e.g., Find students who scored above their own class average&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;SELECT student_id, class, marks&lt;br&gt;
FROM exam_results e1&lt;br&gt;
WHERE marks &amp;gt; (&lt;br&gt;
    SELECT AVG(marks) FROM exam_results e2&lt;br&gt;
    WHERE e2.class = e1.class&lt;br&gt;
);&lt;/p&gt;

&lt;p&gt;When to Use a Subquery;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Quick one-off filters using IN, NOT IN, or EXISTS&lt;/li&gt;
&lt;li&gt;When the logic is short, i.e., one or two lines &lt;/li&gt;
&lt;li&gt;When you only need the result once&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Part 2: CTEs —(Common Table Expression)
&lt;/h1&gt;

&lt;p&gt;A CTE lets you write your inner logic once, give it a name, and then use that name in your main query.&lt;br&gt;
Think of it as giving your subquery a label so everyone knows what it means. You define it at the top of your query.&lt;/p&gt;

&lt;p&gt;Basic Syntax&lt;br&gt;
WITH cte_name AS (&lt;br&gt;
    SELECT ...&lt;br&gt;
    FROM ...&lt;br&gt;
    WHERE ...&lt;br&gt;
)&lt;br&gt;
SELECT * FROM cte_name;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of CTEs&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;Simple CTE -It defines a named result set used once or multiple times in the main query. It is perfect for cleaning up a single layer of complexity.&lt;br&gt;
e.g., Show only doctors with more than 8 years of experience&lt;br&gt;
WITH experienced_doctors AS (&lt;br&gt;
SELECT doctor_id, full_name, specialisation, years_exp&lt;br&gt;
FROM doctors&lt;br&gt;
WHERE years_exp &amp;gt; 8&lt;br&gt;
)&lt;br&gt;
SELECT * FROM experienced_doctors&lt;br&gt;
ORDER BY years_exp DESC;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Multiple CTEs&lt;br&gt;
Defines several named blocks in one WITH clause, separated by commas. Each one can reference the previous, like a logical pipeline.&lt;br&gt;
e.g., Find doctors who charge above the hospital average fee&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;WITH doctor_fees AS (&lt;br&gt;
    SELECT doctor_id, ROUND(AVG(fee), 2) AS avg_fee&lt;br&gt;
    FROM appointments&lt;br&gt;
    GROUP BY doctor_id&lt;br&gt;
),&lt;br&gt;
hospital_avg AS (&lt;br&gt;
    SELECT ROUND(AVG(fee), 2) AS overall_avg&lt;br&gt;
    FROM appointments&lt;br&gt;
)&lt;br&gt;
SELECT d.full_name, df.avg_fee, ha.overall_avg&lt;br&gt;
FROM doctor_fees df&lt;br&gt;
JOIN doctors d     ON d.doctor_id = df.doctor_id&lt;br&gt;
JOIN hospital_avg ha ON df.avg_fee &amp;gt; ha.overall_avg&lt;br&gt;
ORDER BY df.avg_fee DESC;&lt;/p&gt;

&lt;p&gt;3.Recursive CTE&lt;br&gt;
A recursive CTE references itself. It is the only way to handle hierarchical data like a reporting chain or org chart. This is something a regular subquery simply cannot do.&lt;/p&gt;

&lt;p&gt;e.g., Build the full doctor supervision hierarchy&lt;br&gt;
WITH RECURSIVE doctor_hierarchy AS (&lt;/p&gt;

&lt;p&gt;-- Base: doctors with no supervisor (top of the chain)&lt;br&gt;
    SELECT doctor_id, full_name, supervisor_id, 1 AS level&lt;br&gt;
    FROM doctors&lt;br&gt;
    WHERE supervisor_id IS NULL&lt;/p&gt;

&lt;p&gt;UNION ALL&lt;br&gt;
-- Recursive: find doctors supervised by those already found&lt;br&gt;
    SELECT d.doctor_id, d.full_name, d.supervisor_id, dh.level + 1&lt;br&gt;
    FROM doctors d&lt;br&gt;
    JOIN doctor_hierarchy dh ON d.supervisor_id = dh.doctor_id&lt;br&gt;
)&lt;/p&gt;

&lt;p&gt;SELECT * FROM doctor_hierarchy&lt;br&gt;
ORDER BY level, doctor_id;&lt;/p&gt;

&lt;p&gt;The base case finds the top-level doctors (Dr. Amina Omondi, Dr. James Abdi). The recursive case keeps looking for who reports to them, until no more levels exist.&lt;/p&gt;

&lt;p&gt;Here is a comparison between Sub-queries and CTEs&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%2Fvu0jz56lfk1t63qkphrm.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%2Fvu0jz56lfk1t63qkphrm.png" alt=" " width="382" height="383"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Conclusion;&lt;/strong&gt;&lt;br&gt;
Subqueries and CTEs both solve similar problems, but they feel very different to write and to read.&lt;/p&gt;

&lt;p&gt;Use a subquery when your filter is short, simple, and only needed once, especially with IN, NOT IN, and EXISTS.&lt;br&gt;
Use a CTE when your logic grows, when you need to reuse a result, or when someone else needs to read your code.&lt;/p&gt;

&lt;p&gt;Start with subqueries to understand nesting. Proceed to CTEs as your queries grow. Your code will be cleaner, and you definitely will sleep earlier!&lt;/p&gt;

</description>
      <category>postgres</category>
      <category>beginners</category>
    </item>
    <item>
      <title>SQL SET Operators: UNION, INTERSECT, and EXCEPT Explained Simply</title>
      <dc:creator>muriithilydia46-wq</dc:creator>
      <pubDate>Wed, 22 Apr 2026 16:48:02 +0000</pubDate>
      <link>https://forem.com/muriithilydia46wq/sql-set-operators-union-intersect-and-except-explained-simply-cb1</link>
      <guid>https://forem.com/muriithilydia46wq/sql-set-operators-union-intersect-and-except-explained-simply-cb1</guid>
      <description>&lt;p&gt;If you are just starting out with SQL, you have probably already learned how to write a SELECT query, filter data with WHERE, and maybe even join two tables together. But what happens when you need to combine results from two completely different queries? That is exactly where SET operators come in.&lt;/p&gt;

&lt;p&gt;Think of SET operators as tools that let you stack or compare the results of two SELECT queries. Instead of joining tables side by side like a JOIN does, SET operators combine query results on top of each other, row by row.&lt;/p&gt;

&lt;p&gt;There are four SET operators in SQL:&lt;br&gt;
• UNION — combines results and removes duplicates&lt;br&gt;
• UNION ALL — combines results and keeps duplicates&lt;br&gt;
• INTERSECT — returns all the rows that appear in both queries&lt;br&gt;
• EXCEPT — returns results from the first query that do not appear in the second query&lt;/p&gt;

&lt;p&gt;NB: &lt;em&gt;For intersect and except to work, both select statements must have the same number of columns and columns must have compatible data types.  If you try to combine a text column with a number column, PostgreSQL will throw an error.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Let us look at examples for more understanding;&lt;/p&gt;

&lt;h1&gt;
  
  
  UNION
&lt;/h1&gt;

&lt;p&gt;Union combines results Without Duplicates.&lt;br&gt;
I had two tables; one with student data and another with patients data. My task was to show a combined list of all unique cities from the students table and the patients table, ordered alphabetically. This is where UNION came in. See syntax below to solve the query;&lt;/p&gt;

&lt;p&gt;SELECT city FROM nairobi_academy.students&lt;br&gt;
UNION&lt;br&gt;
SELECT city FROM city_hospital.patients&lt;br&gt;
ORDER BY city ASC;&lt;/p&gt;

&lt;p&gt;What UNION does here is take all the cities from students and patients table and combine them into one list, then remove any city that appears more than once. So even if Nairobi appears in both tables, it only shows up once in the final result.&lt;/p&gt;

&lt;h1&gt;
  
  
  UNION ALL
&lt;/h1&gt;

&lt;p&gt;Union All combines results and Keeps everything, including duplicates.&lt;br&gt;
Sometimes you do not want duplicates removed. Maybe you want to see every single name from multiple tables together, with a label showing where each name came from. That is exactly what &lt;em&gt;UNION ALL&lt;/em&gt; does.&lt;/p&gt;

&lt;p&gt;SELECT first_name AS name, 'Student' AS source&lt;br&gt;
FROM nairobi_academy.students&lt;br&gt;
UNION ALL&lt;br&gt;
SELECT full_name AS name, 'Patient' AS source&lt;br&gt;
FROM city_hospital.patients;&lt;/p&gt;

&lt;p&gt;This query gives me one long list with every student name and every patient name. The second column called source tells us whether each name came from the students table or the patients table. &lt;/p&gt;

&lt;h1&gt;
  
  
  INTERSECT
&lt;/h1&gt;

&lt;p&gt;Intersect finds the answer to the question, what do these two queries have in common?&lt;/p&gt;

&lt;p&gt;In my assignment, I used it to find cities that appear in both the students table and the patients table, meaning cities where both students and patients live.&lt;/p&gt;

&lt;p&gt;SELECT city FROM nairobi_academy.students&lt;br&gt;
INTERSECT&lt;br&gt;
SELECT city FROM city_hospital.patients&lt;/p&gt;

&lt;p&gt;Only cities that exist in both results are returned. If a city appears in students but not in patients, it is excluded. &lt;/p&gt;

&lt;h1&gt;
  
  
  EXCEPT
&lt;/h1&gt;

&lt;p&gt;Except helps find what is missing. It returns rows from the first query that do not appear in the second query. This is useful when you want to find missing records.&lt;/p&gt;

&lt;p&gt;For example, if I wanted to find cities where students live but no patients are from, I would write;&lt;/p&gt;

&lt;p&gt;SELECT city FROM nairobi_academy.students&lt;br&gt;
EXCEPT&lt;br&gt;
SELECT city FROM city_hospital.patients;&lt;/p&gt;

&lt;p&gt;This returns only the cities unique to the students table. Any city that also appears in the patients table gets filtered out.&lt;/p&gt;

&lt;h1&gt;
  
  
  Parting shot!
&lt;/h1&gt;

&lt;p&gt;SET operators took me a while to fully grasp, mostly because I kept  mixing up UNION with JOIN. But once I started thinking of them as tools for stacking query results rather than connecting tables, everything clicked. If you are a beginner just getting into SQL, my advice is to practice each operator separately before combining them. Write a simple UNION first, check the result, then move to INTERSECT and EXCEPT. Take it one step at a time and do not be discouraged by the errors, they are part of the learning process. Keep going, it gets better!&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>sql</category>
    </item>
    <item>
      <title>Introduction to SQL: DDL, DML, and Querying Data</title>
      <dc:creator>muriithilydia46-wq</dc:creator>
      <pubDate>Sun, 12 Apr 2026 12:49:25 +0000</pubDate>
      <link>https://forem.com/muriithilydia46wq/introduction-to-sql-ddl-dml-and-querying-data-2n50</link>
      <guid>https://forem.com/muriithilydia46wq/introduction-to-sql-ddl-dml-and-querying-data-2n50</guid>
      <description>&lt;p&gt;As a beginner database administrator, my first assignment was to build a school database for Nairobi Academy from scratch. At first this seemed impossible, especially since I had repeated cases of errors in my queries the whole week. But I soldiered on, ready to research and debug any cases of errors and finish the project. So here is what I learned about SQL this week and some tips;&lt;/p&gt;

&lt;p&gt;"SQL stands for Structured Query Language". We use several languages in SQL, main ones being; DDL (Data Definition Language) &amp;amp; DML (Data Manipulation Language)&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;DDL&lt;/strong&gt; defines database structure using the following commands; CREATE, ALTER, and DROP.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;DML&lt;/strong&gt; simply entails changing data inside the tables. The main commands used are INSERT, UPDATE, SELECT and DELETE&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;em&gt;Think of it this way; DDL builds the house, DML fills it with furniture.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In my current project, the main commands I used were CREATE, INSERT, UPDATE, and DELETE and I will take you through the 'how' shortly.&lt;/p&gt;

&lt;p&gt;I used &lt;strong&gt;CREATE&lt;/strong&gt; to create a schema called nairobi_academy, then CREATE TABLE to build three tables: students, subjects, and exam_results;&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%2Fbmi2xdkvnye63h0c0qwr.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%2Fbmi2xdkvnye63h0c0qwr.png" alt=" " width="395" height="24"&gt;&lt;/a&gt;&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%2F51l1qc0mgeqkbqitc60p.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%2F51l1qc0mgeqkbqitc60p.png" alt=" " width="456" height="23"&gt;&lt;/a&gt;&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%2Fcxi0pgdurxiwno2w2u5b.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%2Fcxi0pgdurxiwno2w2u5b.png" alt=" " width="484" height="23"&gt;&lt;/a&gt;&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%2F29tkdf8r79vdzsl95n0v.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%2F29tkdf8r79vdzsl95n0v.png" alt=" " width="499" height="12"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I also used ALTER TABLE to modify tables after creation, that is; adding a phone_number column, renaming credits to credit_hours, and dropping phone_number when it was no longer needed. This taught me that SQL is flexible and you can always adjust a table's structure even after it has been created.&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%2Fgkoo0iyabgi8qch141nw.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%2Fgkoo0iyabgi8qch141nw.png" alt=" " width="542" height="158"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Next, I used INSERT command, where I added 10 students, 10 subjects, and 10 exam results into the database -see example below;&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%2Fyprn8d8p2n3tbzfdz355.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%2Fyprn8d8p2n3tbzfdz355.png" alt=" " width="608" height="262"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I then used UPDATE command and corrected data that had changed. For instance; updating Esther's city from Nakuru to Nairobi, and fixing incorrect marks from 49 to 59.&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%2Foqzsiygglxvxprm3vwbu.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%2Foqzsiygglxvxprm3vwbu.png" alt=" " width="362" height="63"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, I used DELETE command to remove a cancelled exam result from the table.&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%2F7hh2n6gdljb0oifq551w.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%2F7hh2n6gdljb0oifq551w.png" alt=" " width="445" height="45"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;NB: The most important lesson with &lt;strong&gt;UPDATE&lt;/strong&gt; and &lt;strong&gt;DELETE&lt;/strong&gt; is that, always use a WHERE clause, else every single row in the table gets affected and will be deleted.&lt;/p&gt;

&lt;p&gt;Another key lesson has been how to use SQL filtering functions e.g., WHERE, SEARCH, IN, NOT IN, COUNT &amp;amp; CASE WHEN. &lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;WHERE&lt;/strong&gt; clause filters rows based on conditions while &lt;strong&gt;CASE WHEN&lt;/strong&gt; works like an if-else statement. It creates new labels based on conditions without changing the original data.&lt;/p&gt;

&lt;p&gt;examples;&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%2F41nzqp98m91f52pxjpkw.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%2F41nzqp98m91f52pxjpkw.png" alt=" " width="470" height="65"&gt;&lt;/a&gt;&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%2F6f0i6fqy0pcqe49703gf.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%2F6f0i6fqy0pcqe49703gf.png" alt=" " width="527" height="119"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The biggest challenge this week was managing errors when running scripts multiple times. Some errors I encountered today was "relation already exists" and it kept appearing till it got frustrating. I learned that using IF NOT EXISTS and DROP SCHEMA CASCADE solves this cleanly.&lt;/p&gt;

&lt;p&gt;I also learned the hard way that column names matter. For instance; renaming credits to credit_hours after inserting data caused errors because the INSERT still referenced the old name. Order really matters in SQL! Do not give up when creating and querying data in SQL, remain calm, research on how to debug and &lt;strong&gt;you've got it!&lt;/strong&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>postgres</category>
      <category>database</category>
      <category>sql</category>
    </item>
    <item>
      <title>How to publish a Power BI report and embed it in a website.</title>
      <dc:creator>muriithilydia46-wq</dc:creator>
      <pubDate>Sun, 05 Apr 2026 10:26:57 +0000</pubDate>
      <link>https://forem.com/muriithilydia46wq/how-to-publish-a-power-bi-report-and-embed-it-in-a-website-1035</link>
      <guid>https://forem.com/muriithilydia46wq/how-to-publish-a-power-bi-report-and-embed-it-in-a-website-1035</guid>
      <description>&lt;p&gt;Power BI is a tool created by Microsoft to turn raw data into interactive insights. &lt;/p&gt;

&lt;p&gt;The publishing process entails the below key steps; &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Creating a workspace&lt;/li&gt;
&lt;li&gt;Publishing power BI report&lt;/li&gt;
&lt;li&gt;Creating an embedded code&lt;/li&gt;
&lt;li&gt;Embedding the report on a Website&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here is a detailed process of the step by step process flow for a successful publishing.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1.Creating a workspace.&lt;/strong&gt;&lt;br&gt;
Open a browser and sign in with Microsoft account. Use below link,&lt;br&gt;
&lt;a href="https://app.powerbi.com" rel="noopener noreferrer"&gt;https://app.powerbi.com&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Select “Workspaces” on the left navigation pane, then click “New workspace”&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%2Fuefb0t3oqlnm6qatwz0d.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%2Fuefb0t3oqlnm6qatwz0d.png" alt=" " width="711" height="355"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Fill in the details populated, then click “apply”. This auto-populates your new workspace.&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%2Fzhgka5zatja7muogtigo.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%2Fzhgka5zatja7muogtigo.png" alt=" " width="800" height="149"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Publishing Power BI reports&lt;/strong&gt;&lt;br&gt;
Having created your own workspace, you can now upload your report using the below steps;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Open your finished report in Power BI desktop&lt;br&gt;
Click “publish” on the Home tab;&lt;/p&gt;
&lt;/blockquote&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%2Fxsjqhqq7a88zga8rfh9v.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%2Fxsjqhqq7a88zga8rfh9v.png" alt=" " width="800" height="78"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Select a destination (the workspace you had created earlier), then click select;&lt;/p&gt;
&lt;/blockquote&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%2Fiy0fpe6lo4op7c3ecjct.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%2Fiy0fpe6lo4op7c3ecjct.png" alt=" " width="670" height="273"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The report is automatically uploaded in your workspace. Check your workspace to verify the uploaded data.&lt;/p&gt;

&lt;p&gt;To open the report, click on it and it will automatically open.&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%2Ff188jtzxdrnu5uywhg08.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%2Ff188jtzxdrnu5uywhg08.png" alt=" " width="500" height="108"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Create an Embedded Code.&lt;/strong&gt;&lt;br&gt;
There are three different ways to embed a report; &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Publish to web (Public)&lt;/strong&gt; &lt;br&gt;
Power BI gives you an iframe code you can drop into any website. It makes your report publicly accessible to anyone with the link. It is therefore not suitable for confidential reports. Here is how you go about it;&lt;/p&gt;

&lt;p&gt;Open your published report in Power BI service, then under the report menu, &lt;em&gt;click file &amp;gt;Embed report&amp;gt;Publish to web;&lt;/em&gt;&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%2Fxeamq6pf5t9pg2y1old6.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%2Fxeamq6pf5t9pg2y1old6.png" alt=" " width="725" height="392"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;*&lt;em&gt;Secure Embed (internal use). *&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Viewers need to log in with their Microsoft account to see it. Great for internal company pages like a SharePoint site or Teams tab. It keeps the data protected without much technical setup.&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%2Fh2fhzrbdnwt95cp7f0bj.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%2Fh2fhzrbdnwt95cp7f0bj.png" alt=" " width="702" height="344"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Build it into your app (Developer route).&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This one is for when you're building a product for a client for instance, and where they do not have Power BI Licenses. e.g., a SaaS tool. It requires more setup (you'll need to work with Azure and the Power BI API), but it's the most powerful and flexible option.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;4.Embedding the report on a Website;&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Click File in the top menu &lt;/li&gt;
&lt;li&gt;Select Embed report → Publish to web (public) &lt;/li&gt;
&lt;li&gt;Click Create embed code &lt;/li&gt;
&lt;li&gt;Copy the iframe code that appears to your text editor (Vs code)&lt;/li&gt;
&lt;li&gt;Create a folder in your desktop and name it deploying/publishing.&lt;/li&gt;
&lt;li&gt;Open the folder in VS code and click select. &lt;/li&gt;
&lt;/ul&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%2F9911q3femfgabphn40mw.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%2F9911q3femfgabphn40mw.png" alt=" " width="434" height="264"&gt;&lt;/a&gt;&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%2Fl1s4wgwiswrjcsci73wm.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%2Fl1s4wgwiswrjcsci73wm.png" alt=" " width="458" height="70"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;under the folder, create a new file, i.e., index.html&lt;/li&gt;
&lt;/ul&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%2Ffa041o5u0xkpnwvhpkyj.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%2Ffa041o5u0xkpnwvhpkyj.png" alt=" " width="286" height="44"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Open this website in your browser &lt;a href="https://www.w3schools.com/html/" rel="noopener noreferrer"&gt;https://www.w3schools.com/html/&lt;/a&gt; and copy the html code and paste it in your text editor and save.&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%2F4tf9lolmcb3p43kniip8.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%2F4tf9lolmcb3p43kniip8.png" alt=" " width="381" height="364"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Go to the folder created in desktop (deploying/publishing) and select the folder, then click index;&lt;/li&gt;
&lt;li&gt;Copy the url generated and copy it to your browser;&lt;/li&gt;
&lt;li&gt;Go back to text editor (VC code) and delete “this is a paragraph)&lt;/li&gt;
&lt;li&gt;History copy (windows + V) on the line you have deleted and it select iframe (the embedded code)&lt;/li&gt;
&lt;li&gt;Copy the code above and go back to your browser and refresh.&lt;/li&gt;
&lt;li&gt;You will get a sign in prompt, proceed to sign in;&lt;/li&gt;
&lt;li&gt;After signing in, your report automatically load;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In conclusion, learning power BI has been an eye opening experience as a beginner data analyst. Going in, I expected it to be mostly about making charts look good, but I quickly realised that the real work happens long before you touch a single visual. Cleaning messy data and building a solid model is where most of your time and energy actually goes. Publishing felt like a milestone and is genuinely satisfying. Learning different ways of embedding reports as well felt more like a professional lesson, to ensure I do not publish publicly confidential information and face data breach suits. &lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
    </item>
    <item>
      <title>How excel is used in Real-World Data Analysis</title>
      <dc:creator>muriithilydia46-wq</dc:creator>
      <pubDate>Thu, 26 Mar 2026 18:48:50 +0000</pubDate>
      <link>https://forem.com/muriithilydia46wq/how-excel-is-used-in-real-world-data-analysis-2la5</link>
      <guid>https://forem.com/muriithilydia46wq/how-excel-is-used-in-real-world-data-analysis-2la5</guid>
      <description>&lt;p&gt;Microsoft Excel is a spreadsheet software that allows you to collect, organize, analyze, calculate, and visualize data efficiently. It organizes data into a grid of rows and columns, where each intersection is called a cell. Each cell can hold text, numbers, dates, or formulas that perform calculations automatically.&lt;/p&gt;

&lt;p&gt;In real world, excel has been widely used in data analysis. For instance, where large data sets are involved, excel becomes instrumental in organizing the data and creating a dashboard for visualization. In essence this makes the data easily consumable for insights by management and aids in decision making.&lt;/p&gt;

&lt;p&gt;In my first week of study as a data analyst, I have come to appreciate the capabilities of excel. What has really intrigued me is data clean up, use of pivot tables, charts and creating an interactive excel dashboard.&lt;/p&gt;

&lt;p&gt;Did you know you can remove extra spaces from your text using text functions? Just use the following formula;'=TRIM(text)'. Additionally, you can combine two columns using the function "Concatenate". Here is how; =Concatenate(text). You have to specify if you need a separator, such that you put the space in parenthesis e.g. '=CONCATENATE(A2, " ", B2)'&lt;/p&gt;

&lt;p&gt;The most insightful lesson has been on using pivot tables to show case relationship analysis, and using the pivot tables as primary data source for creating charts and excel dashboard.&lt;/p&gt;

&lt;p&gt;A &lt;em&gt;PivotTable&lt;/em&gt; is a tool that automatically summarizes large amounts of data. Instead of writing formulas, you simply drag and drop fields to group and calculate your data.&lt;br&gt;
Example use: You have 5,000 rows of sales data. A PivotTable can instantly show you total sales per region per month instantly.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Drag a field to rows - groups your data e.g., by product category&lt;/li&gt;
&lt;li&gt;Drag a field to values -calculates totals, count, average, Mid etc.,&lt;/li&gt;
&lt;li&gt;Drag a field to filters -narrows down the criteria of what to see. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;NB: &lt;em&gt;Slicers are also used in place of filters. To insert a slicer, click inside any pivot table, Go to insert tab, click "slicer" and then select the fields you want slicers for&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Charts&lt;/em&gt; visualize your data so patterns and trends are easier to understand. Excel offers many chart types, most commonly used being; bar chart, line chart, pie chart and column chart.&lt;/p&gt;

&lt;p&gt;Lastly, creating an interactive dashboard on excel is the main output for visualization. You start by creating a title for your dashboard and KPIs by inserting a shape. You then copy the pivot tables previously mapped from your data source and insert slicers. Ideally, slicers should be  on the left side, while KPIs should be on top. You then right click on the slicers then click "report connections". This was the dashboard is now interactive.&lt;/p&gt;

&lt;p&gt;Lastly, you create an excel dashboard using pivot tables as the source data, but first you need to write the title of your dashboard and the KPIs.&lt;/p&gt;

&lt;p&gt;The next step is to copy the pivot tables previously mapped into the dashboard, including slicers. You then create connections for the slicers such that any change is reflected in all charts.&lt;/p&gt;

&lt;p&gt;Excel has been life changing to me and I am already utilizing some of the skills learnt so far in my day to day work activities.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>dataanalysis</category>
      <category>excel</category>
    </item>
  </channel>
</rss>
