<?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>Future: Brenda Mutai</title>
    <description>The latest articles on Future by Brenda Mutai (@brenda_mutai_8a282e86666a).</description>
    <link>https://future.forem.com/brenda_mutai_8a282e86666a</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%2F3407560%2Faf06fa11-d91b-4463-bbc5-bd69acd3e1d5.jpg</url>
      <title>Future: Brenda Mutai</title>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://future.forem.com/feed/brenda_mutai_8a282e86666a"/>
    <language>en</language>
    <item>
      <title>Bayesian vs Frequentist</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Fri, 17 Oct 2025 08:29:47 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/bayesian-vs-frequentist-4b97</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/bayesian-vs-frequentist-4b97</guid>
      <description>&lt;p&gt;In statistics, there are two main schools of thought for making inferences from data. &lt;strong&gt;Frequentist&lt;/strong&gt; and the &lt;strong&gt;Bayesian&lt;/strong&gt; approaches aim to answer the same questions, such as estimating parameters, testing hypotheses or predicting future outcomes, but they differ in how they interpret probability and uncertainty.&lt;br&gt;
&lt;code&gt;Flip a coin. Before you look at the result, pause and ask: What’s the probability the coin landed on heads?&lt;/code&gt;&lt;br&gt;
Depending on your answer, you’re either a Frequentist or a Bayesian statistically speaking, at least.&lt;br&gt;
According to a &lt;strong&gt;Frequentist statistical&lt;/strong&gt; approach, there’s a single correct answer. If the coin is heads, the probability that the coin landed on heads is 100%. If it’s tails, the probability is 0%.&lt;br&gt;
In &lt;strong&gt;Bayesian statistics&lt;/strong&gt;, probabilities are interpreted subjectively. Using the coin toss as an example, a Bayesian would say that the probability of getting heads or tails reflects your personal belief. You might start by assuming there’s an equal 50% chance for each side, but your confidence in the coin’s fairness could shape that belief. After observing the outcome, you would then revise or update your belief in light of the new evidence.&lt;br&gt;
The main difference between the two methodologies is how they handle uncertainty. Frequentists rely on long-term frequencies and assume that probabilities are objective and fixed. Bayesians embrace subjectivity and the idea that probabilities change based on new information.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Bayesian vs Frequentist</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Fri, 17 Oct 2025 08:07:45 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/bayesian-vs-frequentist-4cno</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/bayesian-vs-frequentist-4cno</guid>
      <description>&lt;p&gt;In statistics, there are two main schools of thought for making inferences from data. &lt;strong&gt;Frequentist&lt;/strong&gt; and the &lt;strong&gt;Bayesian&lt;/strong&gt; approaches aim to answer the same questions, such as estimating parameters, testing hypotheses or predicting future outcomes, but they differ in how they interpret probability and uncertainty.&lt;br&gt;
&lt;code&gt;Flip a coin. Before you look at the result, pause and ask: What’s the probability the coin landed on heads?&lt;/code&gt;&lt;br&gt;
Depending on your answer, you’re either a Frequentist or a Bayesian statistically speaking, at least.&lt;br&gt;
According to a &lt;strong&gt;Frequentist statistical&lt;/strong&gt; approach, there’s a single correct answer. If the coin is heads, the probability that the coin landed on heads is 100%. If it’s tails, the probability is 0%.&lt;br&gt;
In &lt;strong&gt;Bayesian statistics&lt;/strong&gt;, probabilities are interpreted subjectively. Using the coin toss as an example, a Bayesian would say that the probability of getting heads or tails reflects your personal belief. You might start by assuming there’s an equal 50% chance for each side, but your confidence in the coin’s fairness could shape that belief. After observing the outcome, you would then revise or update your belief in light of the new evidence.&lt;br&gt;
The main difference between the two methodologies is how they handle uncertainty. Frequentists rely on long-term frequencies and assume that probabilities are objective and fixed. Bayesians embrace subjectivity and the idea that probabilities change based on new information.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Importance of Skewness and Kurtosis in EDA</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Tue, 30 Sep 2025 10:29:27 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/the-importance-of-skewness-and-kurtosis-in-eda-5c07</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/the-importance-of-skewness-and-kurtosis-in-eda-5c07</guid>
      <description>&lt;p&gt;Once the data has been collected and carefully cleaned, the next step is to dive into exploring it. This process, called Exploratory Data Analysis (EDA), plays a vital role in any data project. The insights uncovered during EDA guide and influence the decisions made throughout the entire workflow.&lt;br&gt;
A key activity in EDA is examining the distribution shapes of your variables. Understanding these shapes directly impacts later decisions, including:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Preprocessing steps&lt;/li&gt;
&lt;li&gt;Feature selection strategies&lt;/li&gt;
&lt;li&gt;Algorithm selection&lt;/li&gt;
&lt;li&gt;Detecting outliers and deciding if to remove them&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While visualization is useful, it’s often necessary to have numerical measures for greater reliability. Two important metrics for this are &lt;strong&gt;skewness&lt;/strong&gt; and &lt;strong&gt;kurtosis&lt;/strong&gt;, which help evaluate how closely your data’s distribution aligns with the ideal normal distribution.&lt;/p&gt;
&lt;h2&gt;
  
  
  SKEWNESS
&lt;/h2&gt;

&lt;p&gt;Skewness is a statistical measure that captures the asymmetry of a distribution around its mean. In a perfectly normal distribution, both tails are balanced, but if one side extends farther than the other, the data becomes skewed. Skewness quantifies the extent of this imbalance.&lt;br&gt;
Accurately identifying and measuring skewness helps reveal how data values are distributed around the mean and guides the selection of appropriate statistical methods or transformations. For example, when a distribution is highly skewed, applying normalization or scaling can make it closer to a normal distribution, which in turn can improve model performance.&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%2F5ko9aomyuonrrhrbddl5.jpg" 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%2F5ko9aomyuonrrhrbddl5.jpg" alt=" " width="390" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Types of Skewness&lt;/strong&gt;&lt;br&gt;
There are three types of skewness: positive, negative, and zero skewness.&lt;br&gt;
&lt;em&gt;1.Zero skewness&lt;/em&gt;&lt;br&gt;
Zero skewness means the distribution is perfectly symmetrical around its mean. &lt;strong&gt;The mean, median, and mode are all at the center point.&lt;/strong&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%2Fh4ecrqgo96n980gx3xaw.jpg" 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%2Fh4ecrqgo96n980gx3xaw.jpg" alt=" " width="259" height="148"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;2.Positive skewness&lt;/em&gt;&lt;br&gt;
A positively skewed (right-skewed) distribution has a longer right tail, with &lt;strong&gt;the mean greater than the median and the mode being the smallest&lt;/strong&gt;. Most values cluster on the left, while a few extreme values stretch the distribution to the right.&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%2F26f66kgntj97nas9x787.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%2F26f66kgntj97nas9x787.png" alt=" " width="251" height="201"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;3. Negative skewness&lt;/em&gt;&lt;br&gt;
A negatively skewed (left-skewed) distribution has a longer left tail, &lt;strong&gt;with the mean less than the median and the mode being the largest&lt;/strong&gt;. Most values cluster on the right, while extreme values pull the distribution to the left.&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%2Foe0yy3u34gu4awelbmnt.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%2Foe0yy3u34gu4awelbmnt.png" alt=" " width="264" height="191"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to calculate skewness&lt;/strong&gt;&lt;br&gt;
There are many ways to calculate skewness.&lt;br&gt;
_a. Pearson’s second skewness coefficient _&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;this is also known as median skewness.&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%2F3hqfwvmefym64zhemqji.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%2F3hqfwvmefym64zhemqji.png" alt=" " width="733" height="470"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Let’s implement the formula manually in Python:
&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import pandas as pd

# health dataset
bmi = pd.Series([22, 24, 27, 30, 35, 40, 18, 25, 29, 32])

mean_bmi = bmi.mean()
median_bmi = bmi.median()
std_bmi = bmi.std()

skewness_bmi = (3 * (mean_bmi - median_bmi)) / std_bmi

print(
    f"The Pearson's second skewness score of BMI distribution is {skewness_bmi:.5f}"
)

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

&lt;/div&gt;


&lt;p&gt;&lt;em&gt;b. Moment-Based Formula (used in statistics libraries)&lt;/em&gt;&lt;br&gt;
The more general definition of skewness uses the third standardized moment:&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%2Fy14kzpwgb63clr01iof6.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%2Fy14kzpwgb63clr01iof6.png" alt=" " width="800" height="217"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;n represents the number of values in a distribution&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;x_i denotes each data point&lt;br&gt;
&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import numpy as np
import pandas as pd

def moment_based_skew(distribution):
    n = len(distribution)
    mean = np.mean(distribution)
    std = np.std(distribution)

    # Formula broken into two parts
    first_part = n / ((n - 1) * (n - 2))
    second_part = np.sum(((distribution - mean) / std) ** 3)

    skewness = first_part * second_part
    return skewness

# Example health dataset: BMI values
bmi = pd.Series([18, 21, 23, 25, 27, 30, 34, 38, 42, 45])

print("Moment-based skewness of BMI distribution:", moment_based_skew(bmi))

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

&lt;/div&gt;


&lt;p&gt;Built-in methods from pandas or scipy:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
from scipy.stats import skew

# BMI values
bmi = pd.Series([18, 21, 23, 25, 27, 30, 34, 38, 42, 45])

# Pandas version
print("Pandas skewness:", bmi.skew())

# SciPy version
print("SciPy skewness:", skew(bmi))

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  KURTOSIS
&lt;/h2&gt;

&lt;p&gt;While skewness describes the asymmetry of a distribution, kurtosis measures its peakedness or flatness. &lt;strong&gt;A high kurtosis means a sharp peak, heavy tails, and a greater chance of extreme values&lt;/strong&gt;. &lt;br&gt;
&lt;strong&gt;Low kurtosis, on the other hand, indicates a flatter peak, lighter tails, and fewer extreme events&lt;/strong&gt;. For reference, a normal distribution has a kurtosis of about 3.&lt;br&gt;
&lt;strong&gt;Types of Kurtosis&lt;/strong&gt;&lt;br&gt;
Based on kurtosis values, distributions are classified into three types:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Mesokurtic (kurtosis = 3, excess = 0): resembles a normal distribution.&lt;/li&gt;
&lt;li&gt;Leptokurtic (kurtosis &amp;gt; 3, excess &amp;gt; 0): tall peak with heavy tails.&lt;/li&gt;
&lt;li&gt;Platykurtic (kurtosis &amp;lt; 3, excess &amp;lt; 0): flatter peak with lighter tails.&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%2F5mz2cacaosei42trrodv.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%2F5mz2cacaosei42trrodv.png" alt=" " width="707" height="630"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How to calculate kurtosis&lt;/strong&gt;&lt;br&gt;
If you want a manual calculation of kurtosis, you can use the following formula:&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%2Ffejsbcbn88eip4ha8u49.jpg" 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%2Ffejsbcbn88eip4ha8u49.jpg" alt=" " width="800" height="410"&gt;&lt;/a&gt;&lt;br&gt;
Where:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;n = number of observations&lt;/li&gt;
&lt;li&gt;ˉx= sample mean&lt;/li&gt;
&lt;li&gt;s = sample standard deviation&lt;/li&gt;
&lt;li&gt;x_i= each data point&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Python, you can calculate kurtosis the same way as skewness, by using Pandas or SciPy.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd
from scipy.stats import kurtosis

# BMI values
bmi = pd.Series([18, 21, 23, 25, 27, 30, 34, 38, 42, 45])

print("Kurtosis of BMI distribution:", kurtosis(bmi))

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

&lt;/div&gt;



&lt;p&gt;In Pandas, kurtosis can be calculated using either &lt;code&gt;kurt&lt;/code&gt;or &lt;code&gt;kurtosis&lt;/code&gt;. The kurt method works only with Series objects, while kurtosis can be applied to entire DataFrames.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import pandas as pd

#health dataset
health = pd.DataFrame({
    "BMI": [18, 21, 23, 25, 27, 30, 34, 38, 42, 45],
    "BloodPressure": [110, 115, 120, 118, 125, 130, 135, 140, 145, 150],
    "Cholesterol": [160, 170, 175, 180, 185, 190, 200, 210, 220, 230]
})

# Kurtosis of a single column (Series)
print("BMI kurtosis:", health["BMI"].kurt())

# Kurtosis of all numeric columns (DataFrame)
print("\nKurtosis of all health metrics:\n", health.kurtosis())

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

&lt;/div&gt;



&lt;p&gt;Skewness and kurtosis are powerful metrics in exploratory data analysis. Skewness helps us understand the asymmetry of a distribution, while kurtosis highlights its peakedness and tail behavior. Together, they provide deeper insights beyond simple measures like mean and variance, guiding decisions on preprocessing, transformations, and model selection. By combining visual inspection with these statistical measures, analysts can better assess data quality and prepare it for reliable modeling.&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>datascience</category>
      <category>machinelearning</category>
    </item>
    <item>
      <title>Similarities Between a Stored Procedure (SQL) and a Python Function</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Mon, 08 Sep 2025 12:56:25 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/similarities-between-a-stored-procedure-sql-and-a-python-function-1ei4</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/similarities-between-a-stored-procedure-sql-and-a-python-function-1ei4</guid>
      <description>&lt;p&gt;SQL stored procedures and python functions seem to live completely in different worlds databases versus programming.&lt;br&gt;
They share various similarities.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Encapsulation of logic
-A stored procedure encapsulates a set of SQL operations.
-A Python function encapsulates a block of Python code.&lt;/li&gt;
&lt;li&gt;Reusability
-A stored procedure multiple times with different parameters.
-A Python function can be invoked whenever needed.&lt;/li&gt;
&lt;li&gt;Use of Parameters&lt;/li&gt;
&lt;li&gt;Stored procedures accept input parameters.&lt;/li&gt;
&lt;li&gt;Python functions accept arguments.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;em&gt;EXAMPLE&lt;/em&gt;&lt;br&gt;
&lt;code&gt;CREATE PROCEDURE GetOrdersByCustomer @CustomerID INT&lt;br&gt;
AS&lt;br&gt;
BEGIN&lt;br&gt;
    SELECT * &lt;br&gt;
FROM orders &lt;br&gt;
WHERE customer_id = @CustomerID;&lt;br&gt;
END;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;4.Return Values&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;A stored procedures can return datasets or output values.&lt;/li&gt;
&lt;li&gt;Python functions return values explicitly using &lt;strong&gt;return&lt;/strong&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;5.Error Handling&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They both can include error handling, stored procedures with TRY...CATCH, Python functions with try...except.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Stored procedures in SQL are like functions in Python both encapsulate reusable logic, accept parameters, and produce results, but they operate in different environments, databases vs. applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>The Difference Between Subqueries, CTEs, and Stored Procedures</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Mon, 08 Sep 2025 11:31:25 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/the-difference-between-subqueries-ctes-and-stored-procedures-15f0</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/the-difference-between-subqueries-ctes-and-stored-procedures-15f0</guid>
      <description>&lt;p&gt;When working with SQL, often at times we will encounter subquery, CTE(Common Table Expression) and stored procedure. All these may look similar since they deal with querying and organizing data, but they each serve a different purpose.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;1. A subquery&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A subquery is a query inside another query. Its often used to fetch intermediate results in the main query.(Think of it as asking a question inside another question)&lt;br&gt;
The main role is to return a set result that the outer query uses to execute.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;EXAMPLE&lt;/em&gt;&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;SELECT first_name, last_name&lt;br&gt;
FROM customers&lt;br&gt;
WHERE customer_id IN (&lt;br&gt;
    SELECT customer_id &lt;br&gt;
    FROM orders &lt;br&gt;
    WHERE total_amount &amp;gt; 500&lt;br&gt;
);&lt;br&gt;
&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When to use the subqueries&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Filtering results (&lt;code&gt;WHERE,EXISTS,IN&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;Calculating aggregated values&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pros of using the subquery is because they are simple and quick to write while the downside is they are harder to read if the queries are complex.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;2. Common Table Expression(CTE)&lt;/strong&gt;&lt;br&gt;
A CTE is defined the WITH clause. It is a temporary result set that exists within the scope of &lt;strong&gt;SELECT&lt;/strong&gt;, &lt;strong&gt;INSERT&lt;/strong&gt;, &lt;strong&gt;DELETE&lt;/strong&gt; or &lt;strong&gt;UPDATE&lt;/strong&gt;. CTEs main role in SQL is to improve readability, maintainability and are great for breaking complex queries into small pieces.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;EXAMPLE&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;code&gt;WITH customer_totals AS (&lt;br&gt;
    SELECT customer_id, SUM(total_amount) AS total_spent&lt;br&gt;
    FROM orders&lt;br&gt;
    GROUP BY customer_id&lt;br&gt;
)&lt;br&gt;
SELECT c.first_name, c.last_name, t.total_spent&lt;br&gt;
FROM customers c&lt;br&gt;
JOIN customer_totals t ON c.customer_id = t.customer_id&lt;br&gt;
WHERE t.total_spent &amp;gt; 500;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;When to use&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;There is no need to create a separate summary table.&lt;/li&gt;
&lt;li&gt;Always uses up-to-date values.&lt;/li&gt;
&lt;li&gt;Keeps queries dynamic and flexible.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The pros of using improves readability and supports repercussions and the cons not reusable across sessions.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;3. Stored Procedure&lt;/strong&gt;&lt;br&gt;
A stored procedure is SQL code saved in the database, which you can call whenever needed. It can include multiple queries, loops, and conditional logic.&lt;br&gt;
The main role of a stored procedure in SQL is to encapsulate and execute a set of SQL statements and procedural logic as a single, pre-compiled unit within the database.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;&lt;strong&gt;EXAMPLE&lt;/strong&gt;&lt;/em&gt;&lt;br&gt;
&lt;code&gt;CREATE PROCEDURE GetVIPCustomers()&lt;br&gt;
BEGIN&lt;br&gt;
    SELECT c.first_name, c.last_name, SUM(o.total_amount) AS total_spent&lt;br&gt;
    FROM customers c&lt;br&gt;
    JOIN orders o ON c.customer_id = o.customer_id&lt;br&gt;
    GROUP BY c.customer_id&lt;br&gt;
    HAVING total_spent &amp;gt; 500;&lt;br&gt;
END;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The pros of reusable, encapsulates complex operations and the cons are harder to debug.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>PostgreSQL Installation Guide for Linux Servers</title>
      <dc:creator>Brenda Mutai</dc:creator>
      <pubDate>Sat, 02 Aug 2025 14:31:12 +0000</pubDate>
      <link>https://future.forem.com/brenda_mutai_8a282e86666a/postgresql-installation-guide-for-linux-servers-21m4</link>
      <guid>https://future.forem.com/brenda_mutai_8a282e86666a/postgresql-installation-guide-for-linux-servers-21m4</guid>
      <description>&lt;p&gt;&lt;strong&gt;Introduction&lt;/strong&gt;&lt;br&gt;
PostgreSQL is an advanced, opensource relational database system known for its performance, extensibility and standards compliance.&lt;br&gt;
Its a go-to choice for developers and database administrators across the globe.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Prerequisites&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Operating system (Ubuntu, CentOS, Debian)&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Stable internet connection&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Terminal&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;User access with &lt;strong&gt;&lt;em&gt;sudo&lt;/em&gt;&lt;/strong&gt; privileges&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Installation guide on ubuntu&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Update your system&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ensuring system package list is up to date before installing new software.&lt;/p&gt;

&lt;p&gt;For Ubuntu&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo apt update &amp;amp;&amp;amp; sudo apt upgrade&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;2.Install PostgreSQL&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;PostgreSQL :Main database&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;PostgreSQL-contrib: Add useful extensions&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;3.Verify Installation&lt;/p&gt;

&lt;p&gt;&lt;code&gt;psql --version&lt;br&gt;
sudo systemctl status postgresql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;PostgreSQL User Setup&lt;/strong&gt;&lt;br&gt;
Switch to the postgress user&lt;/p&gt;

&lt;p&gt;&lt;code&gt;sudo su - postgres&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Access the PostgreSQL prompt.&lt;/strong&gt;&lt;br&gt;
  &lt;code&gt;psql&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Set a password for the postgres user&lt;/strong&gt;&lt;br&gt;
 &lt;code&gt;ALTER USER postgres WITH PASSWORD 'your_secure_password';&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Exit the postgres user.&lt;/strong&gt;&lt;br&gt;
&lt;code&gt;exit&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Post-Installation Tips&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Database users should use strong passwords.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Restrict remote access using a firewall.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Back up your database regularly.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

</description>
    </item>
  </channel>
</rss>
