HexLibraryHexLibrary
</> HexCodeSign inSign up
PythonJavaScriptTypeScriptCC++JavaPHPGoRustRubyBashSQLLuaPerlCOBOLPascalDelphiFortranDartSwiftC#JuliaGroovyRElixirHaskellKotlinScalaClassic ASPClipperMS-DOS
LESSONS
Introduction to SQL (SELECT)Tables (CREATE & INSERT)Filtering (WHERE)Sorting & LimitingAggregate FunctionsUpdate & DeleteJoins (JOIN)
REFERENCE
📖 Overview
🔎 Querying (SELECT)
🗃️ Creating a Table
✏️ Inserting & Modifying Data
🧲 Filtering (WHERE)
🔢 Sorting & Limiting
📊 Aggregate Functions
🔗 Joins (JOIN)
SQL›Introduction to SQL (SELECT)

Introduction to SQL (SELECT)

The basics of database querying: fetching data and creating tables with SELECT.

Simple enough for a 5-year-old to understand

Fetch data with SELECT

SQL is the language for fetching data from databases. The most fundamental command is SELECT.

Your first query
1
CREATE TABLE person(name TEXT, age INTEGER);
Create table.
DatabaseCreate table.
2
INSERT INTO person VALUES ('Alex', 36), ('Linus', 54);
Insert two rows.
DatabaseInsert two rows.
3
SELECT name FROM person;
Get "name" column: Alex / Linus
Output / InputGet "name" column: Alex / Linus
DatabaseOutput / Input
💡 Hint: Every SQL command ends with a semicolon (;). SELECT * retrieves all columns.

🎯 Exercise & Practice

Test what you've learned — answer, write code, check instantly. (2 left)

1.Which command is used to fetch data from a table?
2.Add 3 and 4 using SELECT and return the result.

🎯 Expected output: 7

Loading editor…

About this topic

SQL does something different from other languages: you tell the computer WHAT you want, not HOW to do it. You say "Bring me the rows from this table that match this condition"; the database decides for itself which file to read and in what order. This is called a declarative language.

The skeleton of every query is the same: you use SELECT to state which columns you want, and FROM to specify which table they come from. These two words are the foundation of all SQL; everything else — filtering, sorting, grouping, joining — are layers added on top of this skeleton.

Knowing SQL is not just for software developers. Data analysts, marketers, product managers, and testers also write SQL to generate reports; SQL is expected in most job postings regardless of language preference.

What you will learn

  • Building a basic query with SELECT and FROM
  • Selecting all columns with an asterisk, and specific columns by name
  • Giving aliases to columns
  • Reducing duplicate values to a single value using DISTINCT
  • Limiting the number of returned rows with LIMIT

When to use?

Basic SELECT queries are used when looking at a table's contents for the first time, determining which columns a report will consist of, and performing exploration before data cleaning.

In a production environment, writing out the columns you need by name instead of pulling all columns with an asterisk is a good habit: it is both faster and your query's behavior won't change when a new column is added to the table.

Common mistakes

Wrong

SELECT name FROM users
WHERE city = 'Ankara'
SELECT age FROM users

Since there is no semicolon between the two queries, the database reads it as a single broken expression and throws a syntax error. Putting a semicolon at the end of every statement should become a habit.

Correct

SELECT name FROM users
WHERE city = 'Ankara';

SELECT age FROM users;

Wrong

SELECT name FROM users WHERE city = "Ankara";

In standard SQL, text values are enclosed in SINGLE quotes; double quotes are used for column or table names. Since this query looks for a column named "Ankara", it throws an error similar to "column "Ankara" does not exist".

Correct

SELECT name FROM users WHERE city = 'Ankara';

Wrong

SELECT * FROM orders;

Technically correct, but trying to fetch all data in a table with millions of rows locks up the connection and fills the memory. When exploring, it is always necessary to limit the number of rows.

Correct

SELECT * FROM orders LIMIT 10;

Frequently asked questions

Is SQL a programming language?

Technically no; SQL is a declarative query language. You define what you want, and the database engine decides how to fetch it. You don't write loops or draw on the screen. Still, quite complex logic can be built using conditions, functions, and subqueries.

What is the difference between MySQL, PostgreSQL, and SQL?

SQL is the name of the language; MySQL and PostgreSQL are database systems that speak that language. SELECT, INSERT, UPDATE, and DELETE are the same in both. Differences appear in date functions, text processing, and row limiting syntax — some systems use TOP instead of LIMIT.

Are SQL commands written in uppercase?

Not mandatory, the database accepts lowercase as well. However, writing keywords in UPPERCASE and table/column names in lowercase is a universal convention; it makes it much easier to visually track the structure in long queries.

Summary

SQL is a declarative query language where you define what you want, and the foundation of every query is SELECT and FROM. Strings are enclosed in single quotes, and the number of rows is limited when exploring.

HexLibraryHexLibrary

Learn programming more clearly. Every command is explained line by line with colors, reinforced with runnable exercises, test your code instantly — all in one place, free.

Learn

  • Home
  • Languages & Lessons
  • HexCode

Company

  • About
  • Contact

Legal

  • Privacy Policy
  • Terms of Use

Other Projects

  • HexToolz
  • Free Service Manuals
© 2026 HexLibrary · The clearest way to learn code