Interview's MateSQL Learning
Interview's Mate

SQL Learning

Foundations → production SQL

Visualizer

DSA Visualizer
All 32 lessons
Custom Playground
Try your own examples

Learning

System Design
31 architecture topics
SQL Learning
160 foundations → production topics
AI Engineering
160 LLM → backend topics
Data Science
160 Python → MLOps topics
Data Engineer
160 SQL → streaming topics
Docker
160 Docker learning topics
Kubernetes
160 K8s fundamentals → cloud
Java LearnSoon
Coming soon
Python Learn
Interview Q&A & internals
JavaScript Learn
Closures, async & DOM Q&A
Tech Learn
Search, practise & track Q&A
AI DSA Practice
Solve coding problems
Theme
Home
SQL topics
Lesson 3/ 160
01. SQL Foundations & Relational Concepts

SQL Dialects Overview (PostgreSQL, MySQL, SQL Server, SQLite, Oracle)

Compare major SQL dialects, ANSI core, and where syntax and features diverge.

BeginnerANSI SQL · Dialect Differences3 quiz questions
Practice SQL
In plain wordsDiagramExamples & theoryStep by stepWhen to use itInterview cluesMistakes to avoidQuiz (3)Practice

In plain words

All databases understand basic SQL, but each has its own spellings for some things, like how to say "only the first 10 rows".

Think of it like…

English in India, Britain and the US: the grammar is the same and almost everything is understood, but some words differ (lift vs elevator), and a few phrases mean something else entirely.

Where you’ve seen it

"Top 5 customers by revenue" is … ORDER BY revenue DESC LIMIT 5 in PostgreSQL, MySQL and SQLite, SELECT TOP 5 … in SQL Server, and … FETCH FIRST 5 ROWS ONLY in Oracle and standard SQL (also accepted by PostgreSQL).

Words you’ll hear

ANSI / ISO SQL
The standard that all dialects follow to varying degrees.
Dialect
A database's own syntax, functions and behaviour on top of the standard.
Identifier quoting
"name" (standard, PostgreSQL), name (MySQL), [name] (SQL Server).
Portability
How easily a query moves between databases unchanged.

Visual diagram

Loading interactive diagram

Theory & example queries

Where dialects differ

Syntax: row limiting (LIMIT / TOP / FETCH FIRST), concatenation (|| in PostgreSQL, Oracle and SQLite; CONCAT in MySQL; + in SQL Server), identifier quoting, and auto-increment (IDENTITY, SERIAL, AUTO_INCREMENT). Functions: dates (DATE_TRUNC vs DATE_FORMAT vs DATETRUNC), string length (LENGTH vs LEN), current time (NOW vs GETDATE). Features: upserts, RETURNING vs OUTPUT, ILIKE, FILTER, and MySQL's lack of FULL OUTER JOIN.

Behaviour differs too, which is the more dangerous kind: MySQL compares text case-insensitively under its default collations, CONCAT returns NULL if any argument is NULL in MySQL but not in PostgreSQL, SQL Server's AVG of integers returns an integer, and DDL is transactional in PostgreSQL but commits implicitly in MySQL and Oracle.

Concatenation in three dialects

PostgreSQL: first_name || ' ' || last_name · MySQL: CONCAT(first_name, ' ', last_name) · SQL Server: first_name + ' ' + last_name (or CONCAT, which all three support).

Key takeaway: Syntax differences break loudly; behaviour differences break silently.

Choosing and working across dialects

PostgreSQL is the common default for new applications because of its standards compliance and features (JSONB, extensions, rich indexing). MySQL powers a large share of web applications, SQL Server is common in .NET and enterprise settings, Oracle in large enterprises, and SQLite inside apps and devices. Analytics engines (BigQuery, Snowflake, Redshift, DuckDB) add their own dialects, mostly close to PostgreSQL.

For portable code, prefer standard constructs (CASE over IF, COALESCE over IFNULL/ISNULL, CAST over ::, FETCH FIRST where supported), test on the real target database, and isolate dialect-specific parts behind a query builder or ORM when you genuinely need several databases. In interviews, state the dialect up front ("I'll write this in PostgreSQL").

A portable top-N queryQuery example
1Input dataStart from the source rows or state that the statement sees.
customers
3 rows
customers sample rows
idnameemailcity
1Mayamaya@example.comPune
2Raviravi@example.comDelhi
3Noornoor@example.comMumbai
2QuerySwitch dialects, then select a line or execution step to trace it.
query.sql
1SELECT2  name,3  revenue4FROM5  customers6ORDER BY7  revenue DESC8FETCH FIRST9  5 ROWS ONLY;
Logical execution order
Native / baseline

PostgreSQL is the lesson baseline unless noted otherwise.

Line 1 · Project and calculate

Calculate the selected expressions and return the requested output columns.

1/9
3OutputInspect the representative rows, affected-row count, plan, or command status.
Top five customers by revenue4 sample rows
Top five customers by revenue
namerevenue
Asha Retail125000
Northwind Labs98000
Bluebird Foods76500
Metro Tools54000

Note: Representative sample data; production values and the exact tie order depend on the customers table and dialect syntax.

4ExplanationConnect the result back to the SQL rule and the edge case it demonstrates.

runs in PostgreSQL, Oracle and SQL Server 2012+ (with OFFSET 0 ROWS before FETCH in SQL Server), while LIMIT 5 covers PostgreSQL, MySQL and SQLite.

Key takeaway: Prefer standard functions, test on the target, and name your dialect.

Interactive walkthrough

How it works, step by step

Follow one practical SQL workflow from start to finish. Select any step or play through the flow.

Progress1/4
Step 1Context

Identify the target database

Find out which database (and version) the query will run on before writing anything dialect-specific.

Focus at this step

PostgreSQL 16 · MySQL 8.0 · SQL Server 2022

What to watch at this step
Version
matters too
Tip: use ← → to move between steps

When to use it & trade-offs

What it is

SQL is a standard, but every database speaks its own dialect. The core (SELECT, JOIN, WHERE, GROUP BY, most window functions) works almost everywhere. The differences show up in limiting rows (LIMIT vs TOP vs FETCH FIRST), string concatenation, quoting identifiers, auto-increment columns, upserts, date functions, and features some engines lack, such as FULL OUTER JOIN in MySQL or RETURNING in SQL Server.

Why it matters: Interviews and jobs use different databases, and SQL copied from one into another often fails, or worse, runs and behaves differently. Knowing where dialects diverge lets you write portable queries, read unfamiliar code, and say clearly which dialect you're using in an interview.

When to reach for it

  • Moving SQL between databases
  • Reading code written for a database you don't use daily
  • Answering interview questions in the interviewer's dialect

When to avoid or be careful

  • Assuming SQL from one database behaves the same in another
  • Dialect shortcuts in code meant to be portable
  • Testing only that a translated query runs, not that it returns the same results

Popular SQL databases

PostgreSQL
Best for: General-purpose applications and analytics-friendly features

Strengths: Standards-compliant, JSONB, extensions, transactional DDL.

Watch out: Needs connection pooling at scale; some tuning knowledge.

MySQL / MariaDB
Best for: Web applications and read-heavy workloads

Strengths: Very widely deployed, simple replication, huge ecosystem.

Watch out: Missing FULL JOIN; some lenient defaults and collation surprises.

SQL Server / Oracle
Best for: Enterprise systems with existing licences

Strengths: Mature tooling and features.

Watch out: Licensing cost; dialect-specific syntax (T-SQL, PL/SQL).

Interview signals & numbers to know

When this topic comes up

  • “Which SQL dialect do you use?”
  • “LIMIT doesn't work in SQL Server”
  • Migrating MySQL to PostgreSQL
  • Different results on two databases
  • Choosing a database

Benchmarks & rules of thumb

3 -
ways to limit rows: LIMIT, TOP, FETCH FIRST
0 -
FULL OUTER JOIN support in MySQL
SQL:2003 -
standard that introduced window functions

Common mistakes & follow-ups

Common interview mistakes

  • Using LIMIT in SQL Server or TOP in PostgreSQL.
  • Moving from MySQL to PostgreSQL and finding email lookups have become case-sensitive.
  • Assuming RETURNING exists in SQL Server (it uses OUTPUT).

Likely interviewer follow-ups

  • How would you limit results to 10 rows in SQL Server, MySQL and Oracle?
  • What differences would you watch for when migrating from MySQL to PostgreSQL?
  • Which constructs would you use to keep SQL portable?
Interview tip: Start interview answers with "I'll write this in PostgreSQL" (or the interviewer's choice). It sets expectations and shows you know dialects differ.

Knowledge check

Loading quiz

Put it into practice

Practice related interview Q&A

Apply SQL Dialects Overview (PostgreSQL, MySQL, SQL Server, SQLite, Oracle) with hands-on SQL practice and interview Q&A.

Open SQL Practice →SQL interview Q&A
Previous topic
Relational Model: Tables, Rows, Columns & Schemas
Next topic
Installing PostgreSQL / MySQL & Database Clients (DBeaver, pgAdmin)