DEV Community

Ali Hamza
Ali Hamza

Posted on

Day 80 of Learning MERN Stack

Hello Dev Community! ๐Ÿ‘‹

It is officially Day 80 of my 100-day full-stack and database engineering streak! ๐ŸŽฏ I have officially crossed 80% of this intense learning run. Yesterday, I focused on structural table checks and aggregation functions. Today, I dove deep into the logical core of database filtering by mastering: SQL Logical Operators (AND, OR, NOT, IN, BETWEEN, LIKE)!

When users search or apply multiple filters on a frontend applicationโ€”like sorting clothes on an e-commerce platform or picking movie genres on a media streaming serviceโ€”the backend relies entirely on these operators to scan massive tabular datasets efficiently.


๐Ÿง  Deep Dive: The Logic Gates of SQL

Today, I built and verified complex query matrices to understand exactly how the SQL engine processes multi-conditional statements:

1. Intersecting & Alternating Conditions (AND, OR, NOT)

  • AND: Strict matching. Evaluates to true only if all wrapped conditions pass.
  • OR: Flexible matching. Returns records if any single independent condition is met.
  • NOT: Negation guard. Reverses the logic state, pulling rows that explicitly do not match the given parameter.

2. Set Matching & Range Boundaries (IN, BETWEEN)

  • IN: Replaces bulky, repetitive OR chains. It lets me pass an array group (e.g., WHERE city IN ('Lahore', 'Karachi')) to scan categorical subsets instantly.
  • BETWEEN: Streamlines numerical and date range boundaries. Instead of writing >= 30 AND <= 50, using BETWEEN 30 AND 50 makes the query incredibly clean and readable.

3. Advanced Pattern Matching (LIKE & Wildcards)

The absolute game-changer for search functionalities! By pairing LIKE with wildcards (% and _), I can run fuzzy text pattern matching:

  • LIKE 'A%' โ€” Grabs any string records starting with the letter "A".
  • LIKE '%m' โ€” Targets strings ending with the letter "m".
  • LIKE '%ali%' โ€” Scans for any strings containing the substring "ali" anywhere inside the column value.

๐Ÿ› ๏ธ Operational Look at the Day 80 Script Architecture

Here is how I synthesized these logical blocks into real-world relational operations:


sql
-- Combining Range parameters with Category sets
SELECT name, age, city 
FROM student 
WHERE (age BETWEEN 20 AND 35) AND city IN ('Karachi', 'Lahore', 'Islamabad');

-- Running negation and search wildcards simultaneously
SELECT * 
FROM student 
WHERE city NOT IN ('Faisalabad') AND name LIKE 'A%';
Enter fullscreen mode Exit fullscreen mode

Top comments (0)