What Is SQL Syntax?
SQL syntax is the set of rules and structure that governs how you write instructions for a database. Think of it as the grammar of SQL — just like English has rules for forming sentences, SQL has rules for forming statements.
Every SQL statement is built from keywords, clauses, expressions, and operators arranged in a specific order. If you break a syntax rule, the database will return an error instead of a result.
Here is a simple example to see SQL syntax in action:
SELECT Name, City
FROM Customers
WHERE City = 'Mumbai'
ORDER BY Name;
+----------------+---------+ | Name | City | +----------------+---------+ | Amit Patel | Mumbai | | Rahul Sharma | Mumbai | +----------------+---------+
This single statement contains four clauses — SELECT, FROM, WHERE, and ORDER BY — each playing a specific role. Let’s break them down.
Structure of an SQL Statement
Most SQL statements follow a predictable structure. Here are the core components:
| Component | Purpose | Example |
|---|---|---|
| Keywords | Reserved words that tell the database what action to perform | SELECT, FROM, WHERE |
| Clauses | Sections of a statement, each beginning with a keyword | WHERE City = 'Mumbai' |
| Expressions | Values, column names, or calculations that produce a result | Salary * 1.10 |
| Operators | Symbols that compare or combine values | =, >, AND, OR |
| Semicolon | Marks the end of a statement | ; |
💡 Key Rule
Every SQL query must have at least two clauses: SELECT (what columns to show) and FROM (which table to read from). Everything else — WHERE, ORDER BY, GROUP BY — is optional.
The SELECT Statement — Most Common SQL Syntax
The SELECT statement is the most frequently used SQL command. You will explore it in depth in Chapter 3: SQL SELECT. Here is its general syntax:
SELECT column1, column2, ...
FROM table_name
WHERE condition
ORDER BY column ASC|DESC;
Let’s use the Employees table from Chapter 1 to see this in practice:
+----+-----------+------------+--------+--------+
| ID | Name | Department | Salary | City |
+----+-----------+------------+--------+--------+
| 1 | Priya K. | Sales | 55000 | Mumbai |
| 2 | John D. | Marketing | 62000 | London |
| 3 | Arun M. | IT | 78000 | Delhi |
| 4 | Emma W. | Sales | 51000 | Sydney |
| 5 | Ravi S. | IT | 72000 | Mumbai |
+----+-----------+------------+--------+--------+
Example 1 — Select specific columns:
SELECT Name, Department
FROM Employees;
+-----------+------------+ | Name | Department | +-----------+------------+ | Priya K. | Sales | | John D. | Marketing | | Arun M. | IT | | Emma W. | Sales | | Ravi S. | IT | +-----------+------------+
Example 2 — Select all columns using *:
SELECT *
FROM Employees;
The asterisk (*) is a shortcut that means “all columns.” It is useful for quick exploration but should be avoided in production queries because it fetches more data than you usually need.
SQL Keywords Are NOT Case Sensitive
One of the most important syntax rules to remember: SQL keywords are not case sensitive. All three statements below are identical and produce the exact same result:
-- UPPERCASE (Recommended Convention)
SELECT Name FROM Employees;
-- lowercase (Also works)
select Name from Employees;
-- Mixed case (Also works)
SeLeCt Name FrOm Employees;
📌 Best Practice
Always write SQL keywords in UPPERCASE (SELECT, FROM, WHERE) and table/column names in their original case. This makes your queries much easier to read and is the industry-standard convention used by professional developers.
The Semicolon — Statement Terminator
The semicolon (;) marks the end of an SQL statement. It tells the database: “This is a complete instruction — execute it now.”
-- Single statement
SELECT Name FROM Employees;
-- Multiple statements executed together
SELECT Name FROM Employees;
SELECT City FROM Customers;
Some database systems (like MySQL) allow you to omit the semicolon for single queries. However, always include it — it is required when running multiple statements and is considered best practice in all environments.
Single Line vs Multi-Line Statements
SQL does not care about line breaks or extra spaces. A query can be written on a single line or spread across multiple lines. The database sees both versions identically.
Single line (harder to read):
SELECT Name, Department, Salary FROM Employees WHERE Salary > 60000 ORDER BY Salary DESC;
Multi-line (much easier to read):
SELECT Name, Department, Salary
FROM Employees
WHERE Salary > 60000
ORDER BY Salary DESC;
+-----------+------------+--------+ | Name | Department | Salary | +-----------+------------+--------+ | Arun M. | IT | 78000 | | Ravi S. | IT | 72000 | | John D. | Marketing | 62000 | +-----------+------------+--------+
💡 Formatting Tip
Always use the multi-line format — put each clause (SELECT, FROM, WHERE, ORDER BY) on its own line. This is the professional standard and makes debugging much easier, especially in long queries.
SQL Comments
Comments are notes you add to your SQL code for explanation. The database ignores them completely — they exist only for human readers. SQL supports two types of comments:
Single-Line Comments
Use two dashes (--) to comment a single line:
-- This query fetches employees earning over 60K
SELECT Name, Salary
FROM Employees
WHERE Salary > 60000;
Multi-Line Comments
Use /* ... */ to comment across multiple lines:
/*
Author: PK
Purpose: Get high-earning employees
Date: March 2026
*/
SELECT Name, Salary
FROM Employees
WHERE Salary > 60000;
Adding comments to your queries is a highly recommended habit. When you revisit a query weeks later, comments help you instantly understand what the code does and why you wrote it.
Text Values vs Numeric Values
An important syntax rule in SQL is how you handle different data types in your conditions. You will use these rules heavily when learning the SQL WHERE clause in Chapter 5.
Text values must be enclosed in single quotes:
SELECT * FROM Employees
WHERE City = 'Mumbai'; -- ✓ Correct
SELECT * FROM Employees
WHERE Department = 'IT'; -- ✓ Correct
Numeric values do NOT use quotes:
SELECT * FROM Employees
WHERE Salary > 60000; -- ✓ Correct
SELECT * FROM Employees
WHERE ID = 3; -- ✓ Correct
⚠️ Common Mistake
Wrapping numbers in quotes (WHERE Salary > '60000') can cause unexpected behavior in some databases. It may work, but the database treats the value as text and compares it alphabetically instead of numerically. Always keep numbers unquoted.
Most Important SQL Keywords
Here are the SQL keywords you will use most frequently throughout this SQL tutorial course. Each one will be covered in detail in upcoming chapters:
| Keyword | What It Does | Chapter |
|---|---|---|
SELECT |
Specifies which columns to retrieve | Ch 3 |
FROM |
Specifies which table to query | Ch 3 |
WHERE |
Filters rows based on a condition | Ch 5 |
ORDER BY |
Sorts results in ascending or descending order | Ch 7 |
INSERT INTO |
Adds new rows to a table | Ch 8 |
UPDATE |
Modifies existing data in a table | Ch 10 |
DELETE |
Removes rows from a table | Ch 11 |
AND / OR |
Combines multiple conditions | Ch 6 |
LIKE |
Searches for patterns in text | Ch 15 |
JOIN |
Combines rows from two or more tables | Ch 20 |
GROUP BY |
Groups rows that share a value | Ch 25 |
COUNT / SUM / AVG |
Performs calculations on groups of rows | Ch 14 |
For a complete reference of all SQL statements, see the official MySQL SQL statements documentation.
Common SQL Syntax Errors and How to Fix Them
As a beginner, you will encounter syntax errors frequently. Here are the most common mistakes and how to fix them:
| Error | Wrong Syntax | Correct Syntax |
|---|---|---|
| Missing quotes around text | WHERE City = Mumbai |
WHERE City = 'Mumbai' |
| Quotes around numbers | WHERE ID = '3' |
WHERE ID = 3 |
| Missing comma between columns | SELECT Name City |
SELECT Name, City |
| Misspelled keyword | SLECT Name FROM... |
SELECT Name FROM... |
| Missing FROM clause | SELECT Name WHERE... |
SELECT Name FROM Table WHERE... |
| Wrong quote type | WHERE City = "Mumbai" |
WHERE City = 'Mumbai' |
💡 Debugging Tip
When you get a syntax error, read the error message carefully — it usually tells you the exact line and position where the problem is. Start by checking for missing commas, unmatched quotes, and misspelled keywords.
Complete SQL Statement Order
When writing a full SQL query, clauses must appear in a specific order. Here is the correct sequence that the database expects:
SELECT column1, column2 -- 1. What to show
FROM table_name -- 2. Where to look
WHERE condition -- 3. Which rows to filter
GROUP BY column -- 4. How to group
HAVING group_condition -- 5. Filter groups
ORDER BY column ASC|DESC -- 6. How to sort
LIMIT number; -- 7. How many rows
You won’t always use all seven clauses. A simple query may only need SELECT and FROM. But when you use multiple clauses, they must appear in this order — putting WHERE after ORDER BY, for example, will cause a syntax error.
If you work with data regularly, explore our ready-made Dashboard Templates on NextGenTemplates that use SQL-powered data for business reporting.
📺 Visit our YouTube channel @NeoTechNavigators for step-by-step video tutorials and dashboard demos on this topic.
🧪 Try It Yourself
Using the Employees table, write a query that shows the Name and Salary of employees who earn more than 55000, sorted by salary from highest to lowest. Try writing it before looking at the answer below.
Your query should use: SELECT, FROM, WHERE, and ORDER BY
SELECT Name, Salary
FROM Employees
WHERE Salary > 55000
ORDER BY Salary DESC;
Expected Output:
+-----------+--------+ | Name | Salary | +-----------+--------+ | Arun M. | 78000 | | Ravi S. | 72000 | | John D. | 62000 | +-----------+--------+
📝 What You Learned in This Chapter
- SQL syntax is the set of rules defining how statements are structured
- Every query needs at least
SELECTandFROM - SQL keywords (
SELECT,WHERE, etc.) are NOT case sensitive, but the convention is to write them in UPPERCASE - Semicolons (
;) mark the end of a statement — always include them - Text values need single quotes (
'Mumbai'); numbers do not - Use
--for single-line comments and/* */for multi-line comments - SQL clauses must follow a specific order: SELECT → FROM → WHERE → GROUP BY → HAVING → ORDER BY → LIMIT
Frequently Asked Questions
'Mumbai' and 'mumbai' might be treated differently in PostgreSQL but the same in MySQL with default settings.'Hello'). This is the SQL standard and works across all databases. Double quotes are used in some databases (like PostgreSQL) to reference column or table names that contain special characters or are case sensitive — but never for data values.📖 Chapter 2 of 30 — SQL Tutorial on Neotech Navigators



