SQL SELECT Query: Basics of Retrieving Data from Database
🚀 What Will You Learn in This Guide?
This guide teaches SELECT queries, the heart of SQL.
How to query tables in the database, how to remove duplicate data with DISTINCT
and you will learn step by step how to order the results with ORDER BY.
🧠 Technical Summary
Subject: Using SELECT, FROM, DISTINCT, WHERE and ORDER BY in SQL
Purpose: To show data querying, filtering and sorting operations from the database
Steps:
- Creating database and table
- Extracting data with SELECT & FROM
- Remove duplicates with DISTINCT
- Filter by WHERE
- Sorting results with ORDER BY
⚙️ 1. Sample Database and Table Setup
Connect to MySQL
mysql -u genixnode_admin -p
➡️ Logs into the MySQL system.
Create Database
CREATE DATABASE sorgu_vt;
USE sorgu_vt;
➡️ Creates and activates the new database.
Create Volunteers Table
CREATE TABLE gonulluler (
gonullu_id INT UNIQUE,
isim VARCHAR(20),
park VARCHAR(30),
haftalik_hedef INT,
rekor_torba INT,
PRIMARY KEY (gonullu_id)
);
➡️ Creates a volunteer table with basic columns.
Add Sample Data
INSERT INTO gonulluler VALUES
(1, 'Ayten', 'Gülhane Parkı', 3, 5),
(2, 'Can', 'Maçka Parkı', 2, 2),
(3, 'Deniz', 'Maçka Parkı', 2, 1),
(4, 'Efe', 'Yıldız Parkı', 1, 1),
(5, 'Ferda', 'Gülhane Parkı', 2, 7),
(6, 'Gizem', 'Emirgan Korusu', 1, 4),
(7, 'Hakan', 'Gülhane Parkı', 1, 3);
➡️ Adds sample volunteer data to the table.
🔍 2. Querying Data with SELECT and FROM
Single Column Query
SELECT isim
FROM gonulluler;
➡️ Returns only the data in the name column.
Querying Multiple Columns
SELECT park, isim, gonullu_id
FROM gonulluler;
➡️ Selects multiple columns and lists them in the order you specify.
Fetching All Columns
SELECT *
FROM gonulluler;
➡️ Returns all columns sequentially.
🔁 3. Removing Duplicate Data with DISTINCT
Remove Duplicate Parks
SELECT DISTINCT park
FROM gonulluler;
➡️ Lists park names uniquely.
DISTINCT with Multiple Columns
SELECT DISTINCT isim, park
FROM gonulluler;
➡️ It deduplicates rows with exactly the same name and parking values.
🎯 4. Filter by WHERE
Select Data That Meets Specific Conditions
SELECT isim, rekor_torba
FROM gonulluler
WHERE rekor_torba = 4;
➡️ Lists volunteers with a record number of bags of 4.
Operators that can be used in the WHERE statement:
= (equals)
<> (not equal)
<, >, <=, >= (smaller/larger comparison)
📊 5. Sorting with ORDER BY
Ascending Sort (ASC)
SELECT isim, rekor_torba
FROM gonulluler
ORDER BY rekor_torba;
➡️ Sorts the data from smallest to largest.
Descending Sort (DESC)
SELECT isim, rekor_torba
FROM gonulluler
ORDER BY rekor_torba DESC;
➡️ Brings those who break the highest record to the top.
💬 Frequently Asked Questions (FAQ)
- What is the order of operations in SQL queries?
Order: FROM → WHERE → SELECT → ORDER BY. Data is first retrieved from the table, filtered, then selected and sorted.
- How does DISTINCT work on multiple columns?
If the combination of values in all columns is the same, the row is deduplicated.
- Why is SELECT * not recommended?
It reduces performance and carries unnecessary data. Just select the columns you need.
- How do the results come without ORDER BY?
By default, data is listed in the order they were added.
- What does SQL SELECT do?
It reads information from the database, but does not modify it (except for INSERT/UPDATE operations).
🧭 Result
SQL's SELECT statement is the basis of database querying. With this guide, you've gained a solid foundation in extracting data, removing duplicates, and sorting results.
Test your queries now by hosting your data on the powerful, secure and fast GenixNode platform

