Now that you have a basic understanding of what SQL and databases are, it's time to get our hands dirty. In this chapter, we'll set up our working environment and write our very first SQL query using a sample dataset.
🚀 Setting Up the SQL Environment
Before writing queries, we need a place to practice them. You have two main options: Online SQL editors or installing a database locally.
✅ Option 1: Online SQL Editors (Best for Beginners)
These platforms are free and require no setup. Just visit the website and start coding!
| Platform | Features |
|---|---|
| SQL Fiddle | Simple, supports multiple DB engines |
| DB Fiddle | Clean interface, supports MySQL, PostgreSQL |
| W3Schools Tryit | Beginner-friendly, example queries included |
💡Tip: We recommend starting with DB Fiddle— it's clean and easy to use.
✅ Option 2: Install MySQL Locally
If you're serious about learning or planning to work with real-world projects:
-
Download and install MySQL Community Server:
https://dev.mysql.com/downloads/mysql/ - Install MySQL Workbench for GUI-based query writing:
https://dev.mysql.com/downloads/workbench/ - (Optional) Use XAMPP which includes MySQL with a local web server:
https://www.apachefriends.org/index.html
🧑🏫 Sample Dataset for This Course
We'll use the same dataset throughout the course for consistency and better understanding. Here's our table:
studentsTable:
| student_id | name | age | course | marks |
|---|---|---|---|---|
| 1 | Rahul | 20 | SQL | 85 |
| 2 | Priya | 21 | Python | 92 |
| 3 | Aman | 19 | SQL | 78 |
| 4 | Sneha | 22 | Java | 88 |
| 5 | Karan | 20 | SQL | 95 |
Let’s create this table using SQL:
CREATE TABLE students (student_id INT, name VARCHAR(50), age INT, course VARCHAR(50), marks INT);INSERT INTO students (student_id, name, age, course, marks) VALUES(1,'Rahul',20,'SQL',85),(2,'Priya',21,'Python',92), (3,'Aman',19,'SQL',78), (4,'Sneha',22,'Java',88), (5,'Karan',20,'SQL',95);
✍️ Your First SQL Query
Let’s write a simple query to see all the students:
SELECT * FROM students;
🔍 Output:
| student_id | name | age | course | marks |
|---|---|---|---|---|
| 1 | Rahul | 20 | SQL | 85 |
| 2 | Priya | 21 | Python | 92 |
| 3 | Aman | 19 | SQL | 78 |
| 4 | Sneha | 22 | Java | 88 |
| 5 | Karan | 20 | SQL | 95 |
🎉 Boom! You’ve successfully created a table, inserted data, and written your first query!
✅ What You’ve Learned
- How to set up a SQL environment
- How to create a sample table
- How to insert and view data using SQL