Learn SQL From Scratch: 7 Essential SQL Queries Every Beginner Should Know

SQL (Structured Query Language) is an important skill for students, software developers, data analysts, and freshers preparing for technical interviews.

If you are new to SQL, here are seven useful SQL queries explained with simple examples.

For these examples, imagine we have a students table containing id, name, marks, department, and department_id columns.

1. SELECT — Display Data

SELECT * FROM students; 

This displays all records and columns from the students table.

2. WHERE — Filter Records

SELECT * FROM students WHERE marks > 80; 

This displays students who scored more than 80 marks.

3. ORDER BY — Sort Data

SELECT * FROM students ORDER BY marks DESC; 

This sorts students from highest to lowest marks.

4. COUNT — Count Records

SELECT COUNT(*) FROM students; 

This returns the total number of student records.

5. GROUP BY — Group Records

SELECT department, COUNT(*) FROM students GROUP BY department; 

This counts how many students belong to each department.

6. INNER JOIN — Combine Tables

Imagine another table named departments, containing id and department_name.

SELECT students.name, departments.department_name FROM students INNER JOIN departments ON students.department_id = departments.id; 

This combines matching records from the two tables.

7. UPDATE — Modify Records

UPDATE students SET marks = 90 WHERE id = 1; 

This changes the marks of the student whose ID is 1.

Be careful when using UPDATE. Without a WHERE condition, you could update every row in the table.

How to Learn SQL in 30 Days

Week 1: Databases, SELECT, WHERE and ORDER BY.

Week 2: SQL functions, GROUP BY and HAVING.

Week 3: JOINs, subqueries and database relationships.

Week 4: SQL exercises, interview questions and a mini project.

Free SQL Learning Resources

You can practice using:

  • W3Schools SQL Tutorial
  • SQLBolt
  • HackerRank SQL Practice

Final Thoughts

The best way to learn SQL is to practice writing queries regularly. Start with simple examples and gradually build your confidence.

If you prefer a structured workbook, I've also created SQL Mastery in 30 Days: From Zero to Database Confidence, a paid PDF eBook covering SQL lessons, exercises and interview preparation.

Price: ₹149

Explore my SQL workbook

Disclosure: This is my own paid digital eBook.