Skip to content
Home Tutorials Roadmaps Courses
Log in Join free
Tutorials MySQL Introduction to SQL
MySQL Intermediate FREE

Introduction to SQL

Lesson 1 of 16 Intermediate Interactive

SQL (Structured Query Language) is used to manage and query data in databases. MySQL is one of the most popular database systems in the world.

What Can SQL Do?

  • Create, read, update, and delete data (CRUD)
  • Create and modify database tables
  • Join data from multiple tables
  • Filter and sort data
  • Aggregate data (count, sum, average)

Syntax

MYSQL
-- Select all columns from a table
SELECT * FROM students;

-- Select specific columns
SELECT name, email FROM students;

-- Filter with WHERE
SELECT * FROM students WHERE age > 18;

-- Insert data
INSERT INTO students (name, email) VALUES ("Ali", "ali@email.com");

-- Update data
UPDATE students SET age = 26 WHERE id = 1;

-- Delete data
DELETE FROM students WHERE id = 1;
Create Your First Table
SQL
CREATE DATABASE IF NOT EXISTS shop;
USE shop;

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    name VARCHAR(100) NOT NULL,
    email VARCHAR(150) UNIQUE NOT NULL,
    age INT,
    city VARCHAR(50) DEFAULT "Unknown",
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);

DESCRIBE users;

Practice

1
Exercise

Write a SQL query to select all columns from a table called "courses".

Answer
SELECT * FROM courses;
2
Exercise

Write a query to insert a student named "Ali" with age 25.

Answer
INSERT INTO students (name, age) VALUES ("Ali", 25);

Quick Quiz

1

What does CRUD stand for?

CRUD stands for Create, Read, Update, Delete — the four basic database operations.

Interview Questions

WHERE filters rows before grouping/aggregation. HAVING filters groups after GROUP BY. You cannot use aggregate functions (COUNT, SUM, etc.) in WHERE but you can in HAVING.