Software Development

SQL for Beginners: Learn Database Basics with Simple Examples

SQL is one of the most useful skills for developers, analysts and marketers. Learn the core ideas and your first queries in about ten minutes.

SQL (Structured Query Language) is the language used to store, read and change data in relational databases such as SQL Server, MySQL and PostgreSQL. Developers, data analysts and even marketers use it every day, which is why it is worth learning early.

What is a relational database?

A relational database stores data in tables, like spreadsheets. Each table has columns (fields) and rows (records). Tables are connected to each other using keys. For example, a students table and a courses table can be linked through an enrollments table.

Your first queries

Imagine a table named students with columns id, name, city and course.

SELECT: read data

SELECT name, city FROM students;

This returns the name and city of every student.

WHERE: filter rows

SELECT * FROM students WHERE city = 'Ludhiana';

This returns only students from Ludhiana. The * means "all columns".

ORDER BY: sort results

SELECT name FROM students ORDER BY name ASC;

INSERT: add data

INSERT INTO students (name, city, course)
VALUES ('Aman', 'Ludhiana', 'Full Stack .NET');

UPDATE and DELETE: change data

UPDATE students SET city = 'Chandigarh' WHERE id = 5;
DELETE FROM students WHERE id = 7;

Always include WHERE with UPDATE and DELETE. Without it, the change applies to every row.

GROUP BY: summarise data

SELECT course, COUNT(*) AS total_students
FROM students
GROUP BY course;

This counts how many students are in each course. Other useful functions are SUM, AVG, MIN and MAX.

JOIN: combine tables

Suppose enrollments links students to courses with student_id and course_id.

SELECT s.name, c.title
FROM enrollments e
JOIN students s ON s.id = e.student_id
JOIN courses  c ON c.id = e.course_id;

This lists each student with the title of the course they joined. INNER JOIN returns only matching rows, while LEFT JOIN keeps all rows from the left table even when there is no match.

Concepts to learn next

  • Primary and foreign keys to keep data consistent.
  • Normalisation to avoid duplicated data.
  • Indexes to make queries fast.
  • Transactions to make sure related changes succeed or fail together.
  • Subqueries and CTEs for more complex questions.
  • Stored procedures and views for reusable logic.

Practice tips

  • Install a free database (for example SQL Server Express or MySQL) and create your own tables.
  • Use realistic data: students, orders, products or expenses.
  • Write the query yourself before looking at solutions.
  • Never practise UPDATE or DELETE on important data without a backup.

Keep going

SQL is a key part of becoming a full stack developer, as explained in our full stack developer roadmap. Our SQL & Database Design course in Ludhiana takes you from basics to performance tuning with practical exercises. Enquire about the course.