<?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: Mungai Erick Gachuhi</title>
    <description>The latest articles on DEV Community by Mungai Erick Gachuhi (@flymanreek5).</description>
    <link>https://dev.to/flymanreek5</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4182961%2Fe6155a1e-a93f-4e2a-bee2-54e3a35f5e70.jpg</url>
      <title>DEV Community: Mungai Erick Gachuhi</title>
      <link>https://dev.to/flymanreek5</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/flymanreek5"/>
    <language>en</language>
    <item>
      <title>SQL BASICS</title>
      <dc:creator>Mungai Erick Gachuhi</dc:creator>
      <pubDate>Mon, 26 Oct 2026 22:59:42 +0000</pubDate>
      <link>https://dev.to/flymanreek5/sql-basics-5c8a</link>
      <guid>https://dev.to/flymanreek5/sql-basics-5c8a</guid>
      <description>&lt;p&gt;During the past few days I have learned a few basics on SQL and would like to share here.&lt;br&gt;
After the first lesson, 'SELECT * FROM table' felt like enough. However, after the third lesson as well as an assignment, I worked with a hospital database of 15 patients. I have now realized the real power is in asking precise questions: &lt;em&gt;Which patients have no insurance? Whose name starts with K? Who needs a phone call because there is no email on file?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In this article I walk through the operators I practiced in PostgreSQL using DBeaver, with queries from my own assignment.&lt;/p&gt;

&lt;h2&gt;
  
  
  The dataset
&lt;/h2&gt;

&lt;p&gt;I worked with a 'patients' table with columns such as 'first_name,' 'gender,' 'age,' 'county,' and 'admission_date.' Some emails and insurance values were left empty on purpose, which turned out to be very important later.&lt;/p&gt;

&lt;h2&gt;
  
  
  &lt;strong&gt;1. Comparison operators&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;These compare a column with a value: '=', '&amp;lt;&amp;gt;', '&amp;gt;', '&amp;lt;', '&amp;gt;=' and '&amp;lt;='.&lt;br&gt;
Examples include&lt;br&gt;
-- To select patients from Kisumu County.&lt;br&gt;
The code is:&lt;br&gt;
SELECT * FROM patients WHERE county = 'Kisumu';&lt;/p&gt;

&lt;p&gt;-- Patients admitted on or after 1 April 2026&lt;br&gt;
SELECT * FROM patients WHERE admission_date &amp;gt;= '2026-04-01';&lt;/p&gt;

&lt;p&gt;Text and dates go in single quotes; numbers don't. '&amp;lt;&amp;gt; ' means "not equal to," so 'department' &amp;lt;&amp;gt; 'General' returns everyone outside the General department.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. &lt;strong&gt;Logical operators: AND, OR, NOT&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;Logical operators combine conditions. 'AND' needs both conditions to be true, 'OR' needs at least one, and 'NOT' reverses a condition.&lt;/p&gt;

&lt;p&gt;Examples include:&lt;br&gt;
-- Male patients over 40, or anyone with a bill above 150,000 (5 rows)&lt;br&gt;
SELECT * FROM patients&lt;br&gt;
WHERE (gender = 'Male' AND age &amp;gt; 40) OR bill_amount &amp;gt; 150000;&lt;/p&gt;

&lt;p&gt;SQL evaluates 'AND' before 'OR,' just like multiplication comes before addition in math. I still use brackets because they show what I mean, and they protect me when conditions get more complicated.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. &lt;strong&gt;IN and BETWEEN&lt;/strong&gt;
&lt;/h2&gt;

&lt;p&gt;When I needed patients from Nairobi or Mombasa, I first wrote it with &lt;code&gt;OR&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;An example is &lt;br&gt;
SELECT * FROM patients&lt;br&gt;
WHERE county = 'Nairobi' OR county = 'Mombasa';&lt;/p&gt;

&lt;p&gt;'IN' does the same job in a shorter and cleaner way:&lt;/p&gt;

&lt;p&gt;An example is: &lt;br&gt;
SELECT * FROM patients&lt;br&gt;
WHERE county IN ('Nairobi', 'Mombasa');&lt;/p&gt;

&lt;p&gt;'BETWEEN' filters a range, and it &lt;strong&gt;includes both endpoints&lt;/strong&gt;. For example, 'bill_amount BETWEEN 10000 AND 50000' is the same as 'bill_amount &amp;gt;= 10000 AND bill_amount &amp;lt;= 50000'. It works with dates too, and &lt;code&gt;NOT BETWEEN&lt;/code&gt; returns everything outside the range.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Handling NULL
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;NULL&lt;/code&gt; means a value is missing or unknown. It is not zero, and it is not an empty string. To find missing data, use 'IS NULL' or 'IS NOT NULL':&lt;/p&gt;

&lt;p&gt;An example is:&lt;br&gt;
-- Patients with no email address&lt;br&gt;
SELECT * FROM patients WHERE email IS NULL;&lt;/p&gt;

&lt;p&gt;SELECT * FROM patients&lt;br&gt;
WHERE insurance IS NULL AND bill_amount &amp;gt; 10000&lt;/p&gt;

&lt;p&gt;If you're learning SQL too, build a small table and break these operators on purpose. You'll remember the mistakes much better than the rules.&lt;/p&gt;

</description>
      <category>sql</category>
      <category>webdev</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
