Skip to content

Learn online at your pace

Databases & SQL • November 29, 2026 • 8 min read

MySQL vs PostgreSQL vs MongoDB: Which Database Should You Learn First?

The Qtec Mastery

Author

MySQL vs PostgreSQL vs MongoDB: Which Database Should You Learn First?

Once you know what a database is, the next question is which one to learn. Search mysql vs postgresql vs mongodb and you will find strong opinions and very little plain advice. This guide explains how the three differ, what each one is genuinely good at and which one a Kenyan beginner should learn first, so you can stop comparing and start practising.

MySQL and PostgreSQL are relational databases that store data in tables and use SQL. MongoDB is a document database that stores JSON-like documents. For most beginners, learn SQL with MySQL or PostgreSQL first, then pick up MongoDB later if a project needs it.

Databases from Zero, part 6 of 6. Previous: Database Indexes Explained: Why Your Queries Are Slow and How to Fix Them

What is the difference between a relational and a document database?

A relational database stores data in tables with fixed columns. Each table holds one kind of thing, and tables are linked with keys. In our school example, students, courses and payments live in three separate tables, and a FOREIGN KEY links each payment to a student. You combine them at query time with JOINs.

A document database stores each record as a document, which looks a lot like JSON. Related data is often stored inside the same document instead of in another table. A student document might carry its course details and a list of payments inside it.

Neither model is "better". They make different trade-offs:

  • Relational databases enforce structure. The database itself refuses a payment for a student who does not exist.
  • Document databases are flexible. Two documents in the same collection can have different fields, which is handy when your data shape changes often.

What does the same data look like in each?

Here is how you would get Nairobi students with their course and payments in MySQL or PostgreSQL. This query runs unchanged on both, using the tables from earlier in the series:

SELECT s.full_name, c.course_name, p.mpesa_code, p.amount_kes
FROM students s
JOIN courses c ON c.course_id = s.course_id
JOIN payments p ON p.student_id = s.student_id
WHERE s.county = 'Nairobi';

In MongoDB you might store Wanjiku as one document, with the course and payments embedded:

db.students.insertOne({
  full_name: "Wanjiku Kamau",
  phone: "+254712345678",
  county: "Nairobi",
  course: { course_name: "Web Development", fee_kes: 10000 },
  payments: [
    { mpesa_code: "SKA4H7XQ2P", amount_kes: 5000, paid_on: new Date("2026-02-03T10:15:00Z") }
  ]
})

db.students.find(
  { county: "Nairobi" },
  { full_name: 1, course: 1, payments: 1, _id: 0 }
)

Notice the trade-off. MongoDB returns everything in one read, with no JOIN. But if the Web Development fee changes, every student document that copied the old fee needs updating. In the relational version you change one row in courses. This is exactly the problem that normalisation solves.

What is MySQL good at?

MySQL is one of the most widely used open-source databases in the world, and it is easy to get started with.

  • It is everywhere. Almost every shared hosting plan with cPanel includes MySQL or its close relative MariaDB. If you build for small businesses, this matters.
  • It pairs naturally with PHP. WordPress requires MySQL or MariaDB, and Laravel projects very often use MySQL.
  • It is simple to run. Tools like XAMPP, Laragon and MySQL Workbench get a beginner running in minutes.
  • Modern SQL features. MySQL 8 supports window functions, common table expressions (WITH), CHECK constraints and a JSON column type.

Honest weaknesses: some behaviour depends on server settings (for example, how strictly it treats invalid data), and a few advanced features arrived later than in PostgreSQL.

What is PostgreSQL good at?

PostgreSQL (often just "Postgres") is an open-source relational database known for correctness and a deep feature set.

  • Strict and standards-focused. It tends to reject bad data rather than quietly adjusting it.
  • Rich data types. Arrays, JSONB for indexed JSON, ranges, and precise date and time handling.
  • Extensions. PostGIS, for example, adds serious mapping and location queries, useful for delivery, logistics and land data.
  • Popular with Python. Django ships extra PostgreSQL-only features in django.contrib.postgres, and many startups choose it as their default.

The SQL is almost the same as MySQL. Small differences show up in table design. For example, an auto-numbered key in PostgreSQL is usually written like this:

-- PostgreSQL syntax (in MySQL you would write INT AUTO_INCREMENT PRIMARY KEY)
CREATE TABLE courses (
  course_id INT GENERATED ALWAYS AS IDENTITY PRIMARY KEY,
  course_name VARCHAR(100) NOT NULL,
  fee_kes NUMERIC(10,2) NOT NULL
);

Honest weaknesses: it is less common on cheap shared hosting, and it has more settings to learn when you start administering it yourself.

What is MongoDB good at?

MongoDB is the best-known document database. It is a real, capable tool, not just a trend.

  • Flexible schema. Good for data whose shape varies, such as product catalogues where a phone and a sofa have different attributes.
  • Feels natural in JavaScript. Documents look like JavaScript objects, so it is common in Node.js projects (the "MERN" stack: MongoDB, Express, React, Node).
  • Built for scaling out. It was designed to spread data across many servers using sharding.
  • Managed hosting. MongoDB Atlas offers a hosted service, including a free tier for learning.

Honest weaknesses: without a schema, messy data can creep in unless your application enforces rules. Data that is heavily linked, like students, courses and payments, often ends up duplicated or needs extra lookups. MongoDB does support multi-document transactions today, but relational databases were built around them from the start.

MySQL vs PostgreSQL vs MongoDB: side by side

MySQLPostgreSQLMongoDB
Data modelTables (relational)Tables (relational)Documents (JSON-like)
Query languageSQLSQLMongoDB Query API
SchemaFixed, defined up frontFixed, defined up frontFlexible, optional validation
RelationshipsForeign keys and JOINsForeign keys and JOINsEmbedding or $lookup
TransactionsYes (InnoDB)YesYes, multi-document supported
Common pairingPHP, Laravel, WordPressDjango, Python, many startupsNode.js, Express
Easy shared hostingVery commonLess commonRare, usually Atlas
Best forWeb apps, business systemsComplex queries, data integrity, GISVaried, fast-changing data shapes

Which database do Kenyan employers and stacks use?

We will not invent percentages, but if you read Kenyan developer job adverts for a few weeks, you will see a pattern that matches the stacks above:

  • PHP and Laravel roles, agency work and WordPress jobs usually mention MySQL.
  • Python and Django roles, fintech and many startups often mention PostgreSQL.
  • Node.js and MERN roles often mention MongoDB.
  • Data analyst roles almost always ask for SQL, whichever database sits behind it.

The common thread is SQL. Many adverts list "MySQL or PostgreSQL" together because a developer who knows one can work in the other within days.

Which one should you learn first?

Our recommendation is clear: learn SQL with MySQL or PostgreSQL first.

  1. SQL transfers. SELECT, JOIN, GROUP BY and indexes work the same way in both, and the ideas carry over to analytics tools too.
  2. Relational thinking makes you a better designer. Keys, normalisation and constraints teach you to model data carefully, which also helps you design good MongoDB documents later.
  3. It matches most work. Business systems such as school portals, SACCO records and M-Pesa payment logs are naturally relational.

Pick MySQL if you plan to build PHP, Laravel or WordPress sites. Pick PostgreSQL if you are heading towards Python and Django. Then learn MongoDB when a real project or job calls for it. It will take far less time once you understand data modelling.

Common mistakes when choosing a database

  • Choosing MongoDB to avoid learning SQL. You will still need SQL for most jobs and almost all data work.
  • Picking for scale you do not have. A school with 2,000 students does not need sharding. A well-indexed MySQL or PostgreSQL table handles that easily.
  • Switching databases every week. Depth in one beats a little of three.
  • Ignoring hosting. Check what your client's hosting supports before you build.

If you have followed this series from What Is a Database? through SQL JOINs, you already have the foundations. The next step is regular practice on real data.

Learn SQL properly, with guidance

DBMS 1: Database Foundations and SQL is a 10-week online course (KES 20,000) covering the foundations this series introduced, from tables and keys to writing real SQL.

See the course →

Also useful: SQL for Data Analysis (KES 20,000)

Frequently asked questions

Is MySQL or PostgreSQL easier for beginners?

Both are beginner friendly and the SQL is nearly identical. MySQL is slightly easier to install alongside PHP tools like XAMPP, so many beginners start there.

Is MongoDB faster than MySQL?

It depends on the data and the queries. Reading one embedded document can be quick, but heavily linked data is often handled better by a relational database with good indexes.

Can I switch from MySQL to PostgreSQL later?

Yes. Most of your SQL knowledge carries over, and you mainly learn a few differences in data types and table definitions.

Is MariaDB the same as MySQL?

MariaDB started as a fork of MySQL and works much the same for everyday SQL. Many hosts offer it in place of MySQL.

Comments (0)

Comments appear after a quick review. Your email is never shown.

You Might Also Like

What Is a Database? A Beginner's Guide With Real Kenyan Examples

What Is a Database? A Beginner's Guide With Real Kenyan Examples

Every app you use, from your school portal to M-Pesa, keeps its information some...

Read More →
SQL for Beginners: 10 Queries You Will Use Every Day

SQL for Beginners: 10 Queries You Will Use Every Day

Most of the SQL people write at work comes down to about ten patterns. This guid...

Read More →
SQL JOINs Explained Simply: INNER, LEFT and RIGHT JOIN With Examples

SQL JOINs Explained Simply: INNER, LEFT and RIGHT JOIN With Examples

Real databases split information across several tables, so sooner or later you n...

Read More →