SQL Puzzles 🎯

beginner
25 min

SQL Puzzles 🎯

Welcome to the SQL Puzzles tutorial, where we'll learn SQL by solving engaging and practical problems! This tutorial is perfect for beginners and intermediates. Let's dive in! 💡

What is SQL? 📝

SQL (Structured Query Language) is a standard language for managing and manipulating databases. It's used to communicate with databases, creating, modifying, and querying data.

Why SQL Matters? 💡

Understanding SQL is crucial for developers as it helps in creating, managing, and maintaining the data infrastructure of applications and websites.

Getting Started 💡

Before we begin, make sure you have a SQL server installed on your machine. For this tutorial, we'll use sqlite3 which comes pre-installed on many systems.

Creating a Database 📝

Let's create a new database named my_database.

sql
sqlite3 my_database

Creating a Table 📝

Now, let's create a table named students with some columns.

sql
CREATE TABLE students ( id INTEGER PRIMARY KEY, name TEXT, age INTEGER, gender TEXT );

Inserting Data 💡

Time to insert some data into the students table.

sql
INSERT INTO students (name, age, gender) VALUES ('John', 23, 'Male'); INSERT INTO students (name, age, gender) VALUES ('Jane', 22, 'Female');

Querying Data 💡

Now, let's query the data from the students table.

sql
SELECT * FROM students;

Updating Data 💡

Sometimes, we need to update existing data. Let's update John's age.

sql
UPDATE students SET age = 24 WHERE name = 'John';

Deleting Data 💡

If necessary, we can delete data from the table.

sql
DELETE FROM students WHERE name = 'Jane';

SQL Queries 📝

SQL queries are used to retrieve, manipulate, and update data in a database. Here are some basic SQL queries:

  1. SELECT: Retrieves data from a database
  2. INSERT INTO: Inserts new data into a table
  3. UPDATE: Modifies existing data in a table
  4. DELETE: Removes data from a table

Quiz 🎯

Quick Quiz
Question 1 of 1

What SQL command is used to retrieve data from a database?