<?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:  Developer zouraiz</title>
    <description>The latest articles on DEV Community by  Developer zouraiz (@mr_zouraiz).</description>
    <link>https://dev.to/mr_zouraiz</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%2F1503826%2Fdf39394a-d275-4a87-8b23-454956c135d4.png</url>
      <title>DEV Community:  Developer zouraiz</title>
      <link>https://dev.to/mr_zouraiz</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mr_zouraiz"/>
    <language>en</language>
    <item>
      <title>SQL Queries Every Developer Should Know</title>
      <dc:creator> Developer zouraiz</dc:creator>
      <pubDate>Sat, 17 Jan 2026 09:46:33 +0000</pubDate>
      <link>https://dev.to/mr_zouraiz/sql-queries-every-developer-should-know-1jd</link>
      <guid>https://dev.to/mr_zouraiz/sql-queries-every-developer-should-know-1jd</guid>
      <description>&lt;p&gt;Introduction to SQL&lt;br&gt;
If you are a web developer, chances are you have worked with a database at some point. It might be PostgreSQL, MySQL, SQLite, or something else. No matter the stack, SQL is always there behind the scenes.And let’s be honest, few things feel better than writing a single SQL query that returns exactly the data you need. Extra points if it runs fast.In this article, we’ll walk through essential SQL queries every developer should know. Whether you are building APIs, dashboards, or debugging a production issue at 2 AM, these queries are your daily tools.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;SELECT &amp;amp; The Foundation
If SQL were a movie, SELECT would be the origin story. Every meaningful query starts here.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use SELECT to fetch only the data you actually need. While SELECT * looks convenient, it can slow down queries and waste bandwidth, especially on large tables.&lt;/p&gt;

&lt;p&gt;The real power of SELECT comes when you combine it with WHERE, JOIN, and ORDER BY.&lt;/p&gt;

&lt;p&gt;SELECT id, name, email&lt;br&gt;
FROM users;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;WHERE Filtering the Noise
Databases can store millions of rows. WHERE helps you narrow things down to what actually matters.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;You can filter using:&lt;/p&gt;

&lt;p&gt;Comparison operators: =, !=, &amp;lt;, &amp;gt;, &amp;lt;=, &amp;gt;=&lt;br&gt;
Logical operators: AND, OR, NOT&lt;br&gt;
Without WHERE, things can get dangerous. A query like DELETE FROM users; without a condition will delete everything. Always double-check.&lt;/p&gt;

&lt;p&gt;SELECT *&lt;br&gt;
FROM orders&lt;br&gt;
WHERE status = 'completed';&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;INSERT Adding New Data
Whenever a user signs up, places an order, or uploads something, you’ll need INSERT.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Best practices:&lt;/p&gt;

&lt;p&gt;Always specify column names&lt;br&gt;
Use bulk inserts when possible for better performance&lt;br&gt;
Never trust user input. Use parameterized queries or an ORM to prevent SQL injection&lt;br&gt;
INSERT INTO users (name, email)&lt;br&gt;
VALUES ('Alice', '&lt;a href="mailto:alice@example.com"&gt;alice@example.com&lt;/a&gt;');&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;UPDATE Changing Existing Data
Emails change, addresses change, and bugs happen. That’s where UPDATE comes in.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most common and most dangerous mistake is forgetting the WHERE clause. Without it, every row gets updated.&lt;/p&gt;

&lt;p&gt;Tips:&lt;/p&gt;

&lt;p&gt;You can update multiple columns at once&lt;br&gt;
Use transactions in production to stay safe&lt;br&gt;
UPDATE users&lt;br&gt;
SET email = '&lt;a href="mailto:alice@newdomain.com"&gt;alice@newdomain.com&lt;/a&gt;'&lt;br&gt;
WHERE id = 42;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;DELETE Removing Data
When it’s time to clean up old or unused data, DELETE does the job.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use cases:&lt;/p&gt;

&lt;p&gt;Removing expired sessions&lt;br&gt;
Cleaning test data&lt;br&gt;
Deleting old logs&lt;br&gt;
Many production apps use soft deletes by adding a deleted_at column instead of permanently removing records.&lt;/p&gt;

&lt;p&gt;DELETE FROM sessions&lt;br&gt;
WHERE last_active &amp;lt; NOW() - INTERVAL '30 days';&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;JOIN Combining Tables
Real applications don’t live in a single table. JOIN lets you stitch data together.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Become a member&lt;br&gt;
Common types:&lt;/p&gt;

&lt;p&gt;INNER JOIN: Only matching rows&lt;br&gt;
LEFT JOIN: All rows from the left table, even if there is no match&lt;br&gt;
RIGHT JOIN: Opposite of left join&lt;br&gt;
FULL JOIN: Everything from both tables&lt;br&gt;
If your results suddenly double, chances are your join condition is wrong.&lt;/p&gt;

&lt;p&gt;SELECT users.name, orders.amount&lt;br&gt;
FROM users&lt;br&gt;
JOIN orders ON users.id = orders.user_id;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GROUP BY and Aggregate Functions
Perfect for analytics and reports.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Common aggregates:&lt;/p&gt;

&lt;p&gt;COUNT() – number of rows&lt;br&gt;
SUM() – total&lt;br&gt;
AVG() – average&lt;br&gt;
MAX() / MIN() – highest or lowest values&lt;br&gt;
Whenever you use aggregates with non-aggregated columns, GROUP BY is required.&lt;/p&gt;

&lt;p&gt;SELECT status, COUNT(*) AS total&lt;br&gt;
FROM orders&lt;br&gt;
GROUP BY status;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;ORDER BY and LIMIT
Sometimes you only need the latest or top results.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Use cases:&lt;/p&gt;

&lt;p&gt;Latest blog posts&lt;br&gt;
Top users by score&lt;br&gt;
Recent transactions&lt;br&gt;
This combo is also great for pagination when used with OFFSET.&lt;/p&gt;

&lt;p&gt;SELECT *&lt;br&gt;
FROM orders&lt;br&gt;
ORDER BY created_at DESC&lt;br&gt;
LIMIT 10;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;LIKE and Pattern Matching
For basic search functionality, LIKE is simple and effective.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Patterns:&lt;/p&gt;

&lt;p&gt;% matches any number of characters&lt;br&gt;
_ matches a single character&lt;br&gt;
Note: Case sensitivity depends on the database. PostgreSQL uses ILIKE for case-insensitive searches.&lt;/p&gt;

&lt;p&gt;SELECT *&lt;br&gt;
FROM users&lt;br&gt;
WHERE email LIKE '%@gmail.com';&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Subqueries
Sometimes one query needs the result of another. That’s a subquery.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;They are great for readability, but joins are often faster. Use subqueries when clarity matters more than raw performance.&lt;/p&gt;

&lt;p&gt;SELECT name, email&lt;br&gt;
FROM users&lt;br&gt;
WHERE id IN (&lt;br&gt;
  SELECT user_id&lt;br&gt;
  FROM orders&lt;br&gt;
  WHERE amount &amp;gt; 100&lt;br&gt;
);&lt;br&gt;
Final Thoughts: Mastering SQL&lt;br&gt;
This article is part of the “SQL Queries Every Developer Should Know” series.&lt;/p&gt;

&lt;p&gt;Mastering these queries will help you:&lt;/p&gt;

&lt;p&gt;Debug faster by querying the database directly&lt;br&gt;
Build better and faster APIs&lt;br&gt;
Write cleaner backend logic&lt;br&gt;
Impress teammates during code reviews&lt;br&gt;
SQL is not scary. It’s a superpower. And like any skill, the more you practice it, the more confident and unstoppable you become.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>sqlserver</category>
      <category>programming</category>
      <category>ai</category>
    </item>
  </channel>
</rss>
