<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tiffany Wambui</title>
    <description>The latest articles on DEV Community by Tiffany Wambui (@tiff_thua).</description>
    <link>https://dev.to/tiff_thua</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%2F3149261%2F7ed95617-01e4-4cf1-95ed-14e80e547c27.jpg</url>
      <title>DEV Community: Tiffany Wambui</title>
      <link>https://dev.to/tiff_thua</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tiff_thua"/>
    <language>en</language>
    <item>
      <title>A COMPREHENSIVE LOOK INTO SQL : - What a Beginner can learn</title>
      <dc:creator>Tiffany Wambui</dc:creator>
      <pubDate>Wed, 21 May 2025 13:12:04 +0000</pubDate>
      <link>https://dev.to/tiff_thua/a-comprehensive-look-into-sql-what-a-beginner-can-learn-3l6g</link>
      <guid>https://dev.to/tiff_thua/a-comprehensive-look-into-sql-what-a-beginner-can-learn-3l6g</guid>
      <description>&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                DIVING INTO (SQL) USING POSTGRESQL
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;TABLE OF CONTENTS &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Introduction to SQL&lt;/li&gt;
&lt;li&gt;Why SQL is important
&lt;/li&gt;
&lt;li&gt;Database concepts &lt;/li&gt;
&lt;li&gt;Steps to connect to a database and making a table &lt;/li&gt;
&lt;li&gt;
&lt;p&gt;Commands on a table &lt;/p&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;              INTRODUCTION TO SQL 
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;ABBREVIATIONS&lt;br&gt;
SQL - Search Query Language&lt;br&gt;
RDBMS - Relational Database management systems&lt;br&gt;
NON-RDBMS - Non-relational database management systems &lt;/p&gt;
&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;WHY IS SQL IMPORTANT &lt;br&gt;
Structured Query Language (SQL) is a commonly used language for database administration that facilitates tasks like retrieving and manipulating data contained in databases. It is able to help data analysts derive data and make trends. It is also a very powerful tool used to manage databases and execute queries to assist in the deriving of data trends.&lt;/p&gt;

&lt;p&gt;This article is meant to look into the introduction of SQL (Search Query Language) and better beginners on how SQL can be used and interacted with. There are key things we need to look into: -&lt;/p&gt;

&lt;p&gt;KEYWORDS&lt;/p&gt;

&lt;p&gt;Data Analytics - It refers to the process of examining, transforming, &amp;amp; modeling data in order to establish patterns and patterns to make data-driven decisions.&lt;br&gt;
Data Science —Interdisciplinary field that utilizes scientific methods to derive data trends.&lt;br&gt;
Database - This is an organized collection of data; it contains data from 2 types of databases: relational databases that contain structured data (the main type used) and non-relational databases that contains unstructured data. &lt;br&gt;
Database Management Systems —software used to manage the databases that we use; we have (RDBMS) relational database management systems &amp;amp; (Non-RDBMS) non-relational database management systems. A type of RDBMS is PostgreSQL or MySQL an example of Non-RDBMS is Mongodb &lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                   DATABASE CONCEPTS 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;These database concepts are meant to familiarize you with the understanding of what a beginner student will encounter. This knowledge will help them better associate with data&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Concept&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Schema&lt;/td&gt;
&lt;td&gt;A collection of database objects (tables, views, etc.) associated with a database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Search path&lt;/td&gt;
&lt;td&gt;is a list of schema names that PostgreSQL searches in order when you refer to a table without qualifying the schema name.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Table&lt;/td&gt;
&lt;td&gt;A spreadsheet-like structured collection of data with rows and columns&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Rows&lt;/td&gt;
&lt;td&gt;A record in a table that contains data related to one item&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Column&lt;/td&gt;
&lt;td&gt;A particular field or attribute that contains a single sort of data, like a name, email address, or enrollment date&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;_Commands in SQL _&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Select&lt;/td&gt;
&lt;td&gt;Select data from database&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;From&lt;/td&gt;
&lt;td&gt;Specify table we're pulling from&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Where&lt;/td&gt;
&lt;td&gt;Used to filter query to match a specified condition&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;As&lt;/td&gt;
&lt;td&gt;Used in renaming column/table with alias&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Joins&lt;/td&gt;
&lt;td&gt;Is used in the combination of 2 or more rows from tables&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;And&lt;/td&gt;
&lt;td&gt;Combines query conditions that, all conditions must be met&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Or&lt;/td&gt;
&lt;td&gt;Combines query conditions where at least one condition must be met&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Limit&lt;/td&gt;
&lt;td&gt;It is used to show only specific number of rows to be shown&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;In&lt;/td&gt;
&lt;td&gt;Used to specify multiple values when using (WHERE) - Subqueries&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Like&lt;/td&gt;
&lt;td&gt;Looks to identify patterns in a column&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;_Command that make changes in the table _&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Command&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Alter Table&lt;/td&gt;
&lt;td&gt;Add/Remove columns from table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Update&lt;/td&gt;
&lt;td&gt;Update table data&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Create&lt;/td&gt;
&lt;td&gt;Used in inputting TABLES, DATABASE, INDEX&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Insert&lt;/td&gt;
&lt;td&gt;Used to add a single row to a table&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Drop&lt;/td&gt;
&lt;td&gt;Used in the removal or delete from TABLE, DATABASE.&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Commands that are comparison/Aggregate functions&lt;/em&gt;&lt;/p&gt;

&lt;div class="table-wrapper-paragraph"&gt;&lt;table&gt;
&lt;thead&gt;
&lt;tr&gt;
&lt;th&gt;Comparison&lt;/th&gt;
&lt;th&gt;Meaning&lt;/th&gt;
&lt;/tr&gt;
&lt;/thead&gt;
&lt;tbody&gt;
&lt;tr&gt;
&lt;td&gt;Group by&lt;/td&gt;
&lt;td&gt;Combines data in aggregate functions&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Order&lt;/td&gt;
&lt;td&gt;Set order of result, (ASC/DESC) ascending/descending order&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Having&lt;/td&gt;
&lt;td&gt;Similar to the function WHERE but it filters groups.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Count&lt;/td&gt;
&lt;td&gt;It counts the number of rows in a table.&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Sum&lt;/td&gt;
&lt;td&gt;Return the sum total of a column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Avg&lt;/td&gt;
&lt;td&gt;Returns the average of a column&lt;/td&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;td&gt;Min/Max&lt;/td&gt;
&lt;td&gt;Returns the minimum and maximum value of a column&lt;/td&gt;
&lt;/tr&gt;
&lt;/tbody&gt;
&lt;/table&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Data Types in SQL&lt;/em&gt;&lt;br&gt;
What is a data type? It refers to classifications of data; it tells Postgres/MySql how to interpret the data that has been inputted &lt;br&gt;
E.g.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Text/string - It would be denoted by &lt;code&gt;CHAR ()&lt;/code&gt;, &lt;code&gt;VARCHAR()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Numeric - It would be denoted by &lt;code&gt;INT()&lt;/code&gt;, &lt;code&gt;DECIMAL()&lt;/code&gt;, &lt;code&gt;BOOLEAN()&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;Date &amp;amp; Time - It would be denoted by &lt;code&gt;DATE()&lt;/code&gt;,&lt;code&gt;TIME()&lt;/code&gt;, &lt;code&gt;TIMESTAMP()&lt;/code&gt;.
Primary Key - Enables records in a table to be uniquely identified
Foreign Key -Uses the main key of another table to establish a relationship between them.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With that being concluded, we continue with the practical part of the SQL&lt;/p&gt;
&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;             HOW TO CREATE/CONNECT TO A DATABASE
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;
&lt;p&gt;To best illustrate this, we will need to use a project. The project will be on teams of football and their scores. Project Name: - Student Awards &lt;/p&gt;
&lt;h2&gt;
  
  
  Step 1: - Create a database
&lt;/h2&gt;

&lt;p&gt;The first order of business will be to create a database. the database will be called&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create database: student_award;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This database will contain data from students, performance and the awards&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2 - Create a schema
&lt;/h2&gt;

&lt;p&gt;The second step will be to create a schema; the name of the schema will be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;create schema: Daystar02;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This to help use organize our data in line with a schema &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 3 - Create the Students Table
&lt;/h2&gt;

&lt;p&gt;This will be the first table we will use&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Table students (
student_id = SERIAL primary key,
student_name = VARCHAR (50) is not null,
student_age = INT unique not null,
student_email = VARCHAR(100);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This table contains the following: student id, student name, student age, and student email.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 4 - Create the Performance Table
&lt;/h2&gt;

&lt;p&gt;This table will be the second one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Table performance (
Subject_code = SERIAL primary key,
Subject_name = VARCHAR (100),
Subject_score = DECIMAL (10, 2),
Subject_lec = VARCHAR (100);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This table contains the following: subject code, subject name, subject score, and subject lecturer.&lt;/p&gt;

&lt;h2&gt;
  
  
  Step 5 Create the Award Table
&lt;/h2&gt;

&lt;p&gt;This table will be the third one&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Create Table awards (
Awards_code = SERIAL primary key, 
Subject_code = INT,
Student_id = INT,
Year = Date;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 6 Insert into Student Table
&lt;/h2&gt;

&lt;p&gt;This we will be inputting data required for the database&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO daystar01.student (student_id, student_name, student_age, student_email) VALUES
(1, 'Dorothy', 34, 'Dorothy1@gmail.com'),
(2, 'Wambui', 25, 'Wambui2@gmail.com'),
(3, 'Nicole', 23, 'Nicole3@gmail.com'),
(4, 'Mike', 27, 'Mike4@gmail.com'),
(5, 'Rachel', 29, 'Rachel5@gmail.com'), 
(6, 'Lewis', 20, 'Lewis6@gmail.com);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 7 Insert into Performance Table
&lt;/h2&gt;

&lt;p&gt;This will be used to load the information into the performance table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO daystar01. Performance ( subject_code, subject_name, subject_score, subject_lec)
(21, 'Kiswahili', 67.6, 'Dan'),
(22, 'English', 74.5, 'Ted'),
(34, 'Math', 70.3, 'Vanessa'),
(43, 'History', 54.8, 'Peter');
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 8 Insert into Awards Table
&lt;/h2&gt;

&lt;p&gt;This will be used to load the information into the awards table&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;INSERT INTO daystar01. awards (award_code, subject_code, student_id, year)
(7.5, 21, 1, 2023), --- Dorothy took Kiswahili ----
(3.4, 43, 2, 2024), --- Wambui took History ----
(5.2, 34, 3, 2022), --- Nicole took Math ----
(2.3, 43, 4, 2025), --- Mike took History ---
(1.4, 21, 5, 2024), --- Rachel took Kiswahili ---
(5.6, 22, 6. 2023); --- Lewis took English ---

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 9 Retrieving data from the tables
&lt;/h2&gt;

&lt;p&gt;We will now use &lt;em&gt;Select&lt;/em&gt; to get all the information from the tables&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select * from student;
Select * from performance;
Select * from awards; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;                  ## Commands on a table 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;

&lt;p&gt;In order for this to be illustrated, we will need some questions &lt;br&gt;
Questions&lt;br&gt;
1 Retrieve all student names and their ages from the students table (Select Queries)&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Select student_names, student_age
        From students; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Find the average score of all subjects in the performance table. (Aggregate Functions)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT AVG(subject_score) as average_score 
FROM performance;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Find all subjects with scores greater than 70. (Conditional Queries)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT subject_name 
FROM performance 
WHERE subject_score &amp;gt; 70;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;4 Retrieve the list of subjects along with their average scores, but only for those subjects that have an average score greater than 60. Order the results by average score in descending order.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT subject_name, AVG(subject_score) as average_score 
FROM performance 
GROUP BY subject_name 
HAVING AVG(subject_score) &amp;gt; 60 
ORDER BY average_score DESC;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Retrieve the names of students who have a score in any subject that is above the average score of all subjects. (Subqueries)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT s.student_name 
FROM students s 
WHERE s.student_id IN (
    SELECT a.student_id 
    FROM awards a
    JOIN performance p ON a.subject_code = p.subject_code 
    WHERE p.subject_score &amp;gt; (SELECT AVG(subject_score) FROM performance)
);
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ol&gt;
&lt;li&gt;Get the names of students who have received awards, along with the subjects they received awards for. (JOINS)
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;SELECT s.student_name, p.subject_name 
FROM awards a
INNER JOIN students s ON a.student_id = s.student_id
INNER JOIN performance p ON a.subject_code = p.subject_code;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;These are short examples of what a beginner needs to know in SQL. Good luck&lt;/p&gt;

</description>
      <category>sql</category>
      <category>database</category>
      <category>data</category>
      <category>analytics</category>
    </item>
  </channel>
</rss>
