Introduction to SQL: SELECT Queries

  • Admin
  • 1 min read

What is SQL?

SQL (Structured Query Language) is how you talk to relational databases — asking for data, filtering it, and combining it across tables.

The Basic SELECT

SELECT name, email FROM users;

This returns the name and email columns for every row in the users table. Use * to select all columns, though naming columns explicitly is better practice.

Filtering with WHERE

SELECT * FROM users WHERE age >= 18 AND country = 'India';

Sorting and Limiting

SELECT title, views FROM tutorials ORDER BY views DESC LIMIT 10;

Joining Tables

Real data usually lives across multiple related tables. A JOIN combines rows from two tables based on a matching column:

SELECT orders.id, users.name FROM orders JOIN users ON orders.user_id = users.id;

Grouping and Aggregating

SELECT category, COUNT(*) AS total FROM tutorials GROUP BY category ORDER BY total DESC;

Common aggregate functions: COUNT(), SUM(), AVG(), MIN(), MAX().

A Common Beginner Mistake

Forgetting that WHERE filters rows before grouping, while HAVING filters groups after aggregation:

SELECT category, COUNT(*) AS total FROM tutorials GROUP BY category HAVING COUNT(*) > 5;

Practice Exercise

Given a students table and an enrollments table, write a query that lists each student’s name alongside how many courses they’re enrolled in, sorted highest first.

Admin

About the author

Admin

Instructor and technical writer at tutorials.in

Writes beginner lessons for tutorials.in. Each lesson is checked against the language or tool documentation, and examples are run before publishing.

Reviewed by the editorial team before publishing. Last updated August 9, 2026.

Ask a question

Be specific about what you tried. Questions with a code sample and the exact error message are answered fastest.