Search
  • +44-7459919437 (UK- WhatsApp & Direct Call) | +91-6383544892 (India - WhatsApp Only) | Email Id : vinothtechsolutions@gmail.com
Vinoth Tech Solutions
  • Home
  • Tutorials
  • Free Complete QA Video Courses
    • Cypress Automation
    • Cucumber BDD Framework
    • JavaScript for Playwright & Cypress Automation
    • API Manual and Automation Testing using SoapUI
    • Appium 2.0 Mobile Automation
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Playwright Course Curriculum
  • About Me
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • Tech Events & Sessions
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • XPath Demo Page
    • Python JS Online Compiler
    • Python Tutorials
  • Home
  • Tutorials
  • Free Complete QA Video Courses
    • Cypress Automation
    • Cucumber BDD Framework
    • JavaScript for Playwright & Cypress Automation
    • API Manual and Automation Testing using SoapUI
    • Appium 2.0 Mobile Automation
    • DevOps CI CD using Real Time Project Setup
  • Self Paced Video Course
    • Selenium Course Curriculum
    • Playwright Course Curriculum
  • About Me
    • LinkedIn Profile
    • Placed Students Feedback
    • Online Training Feedback
    • Tech Events & Sessions
  • FAQS
  • Demo Sites
    • Practice Automation
      • Registration Form
      • Transaction Details
      • DropDown
      • Basic Authentication
      • Mouse Event
      • Keyboard Events
      • Alert and Popup
      • Multiple Windows
      • iFrames
      • Wait WebElement
      • WebTable
      • Date Picker Calendar
    • E-Commerce Demo Application
    • Healthcare Demo Page
    • Create Account Demo Page
    • XPath Demo Page
    • Python JS Online Compiler
    • Python Tutorials

SQL Tutorials

  • What is SQL?
  • SQL Syntax & Statement Types 
  • SQL SELECT Statement
  • SQL ORDER BY Clause
View Categories
  • Home
  • Tutorials
  • SQL
  • SQL Tutorials
  • SQL SELECT Statement

SQL SELECT Statement

SQL SELECT Statement

The SELECT statement is the foundation of SQL.
If you want to retrieve, view, filter, or analyse data inside a database table, SELECT is the command you’ll use. Every analytics query, API validation script, or reporting logic starts with a SELECT.

This tutorial covers everything you need to know to get started.

1. What Does the SELECT Statement Do?

SELECT is used to retrieve data from one or more tables.
You can choose:

  • Which columns to show

  • Which rows to show

  • How the data should be sorted

  • Whether to remove duplicates

  • Whether to apply expressions or calculations

Basic syntax:

🗃️
SELECT column1, column2, ...

FROM table_name;

2. Selecting All Columns

If you want to fetch all the columns from a table, use the asterisk (*):

🗃️
SELECT *

FROM Employees;

This returns every row and every column in the Employees table.

⚠️ Tip for professionals:
Avoid using SELECT * in production queries. It slows performance and returns unwanted columns. Use only the columns you actually need.

3. Selecting Specific Columns

Instead of selecting all columns, you can list only the columns you need:

🗃️
SELECT FirstName, LastName, City

FROM Employees;

This makes the output cleaner and the query faster.

4. Using Column Aliases (AS)

🗃️
-- Aliases let you rename output columns, making results more readable:

SELECT 

    FirstName AS "First Name",

    Salary AS "Monthly Salary"

FROM Employees;

-- You can also skip the AS keyword:

SELECT FirstName "First Name"

FROM Employees;

Aliases are extremely useful in reporting, joins, and calculations.

5. Selecting Distinct Values (DISTINCT)

If a column contains repeated values, DISTINCT removes duplicates.

🗃️
filename.js
-- Example: Get unique job titles:

SELECT DISTINCT JobTitle

FROM Employees;

-- Example: Unique combinations of department and city:

SELECT DISTINCT Department, City

FROM Employees;

6. Sorting Data with ORDER BY

🗃️
-- The default order is ascending (ASC). Use DESC for descending.

SELECT FirstName, LastName, Salary

FROM Employees

ORDER BY Salary DESC;

-- You can sort by multiple columns:

SELECT FirstName, LastName, City, Salary

FROM Employees

ORDER BY City ASC, Salary DESC;

7. Limiting the Number of Rows

Different databases use different keywords:

🗃️
-- MySQL / PostgreSQL:

SELECT *

FROM Employees

LIMIT 5;

-- SQL Server:

SELECT TOP 5 *

FROM Employees;

-- Standard SQL:

SELECT *

FROM Employees

FETCH FIRST 5 ROWS ONLY;

8. Using Expressions in SELECT

🗃️
-- You can return calculated columns:

SELECT 

    FirstName,

    LastName,

    Salary,

    Salary * 12 AS AnnualSalary

FROM Employees;

-- Example: Concatenate columns:

SELECT

    FirstName || ' ' || LastName AS FullName

FROM Employees;

(Some databases use CONCAT() instead.)

9. SELECT with WHERE (Preview)

🗃️
-- You can apply conditions to filter rows:

SELECT *

FROM Employees

WHERE City = 'London';

You will learn all filtering conditions in the next topic (SQL WHERE).

10. A Complete Practical Example

Imagine a table:

Projects

ProjectIDProjectNameStartDateStatusBudget
1CRM Migration2025-01-10Active40000
2Mobile App Revamp2025-02-15Completed25000
3Data Lake Setup2025-03-01Active60000
🗃️
filename.js
-- Let’s write a useful business query:

SELECT 

    ProjectName AS "Project",

    Budget,

    Budget * 1.2 AS "Revised Budget",

    Status

FROM Projects

WHERE Status = 'Active'

ORDER BY Budget DESC;

Result:

ProjectBudgetRevised BudgetStatus
Data Lake Setup6000072000Active
CRM Migration4000048000Active

This shows how SELECT can combine:

  • Filtering
  • Sorting
  • Aliasing
  • Expressions

11. Summary Checklist

By now, you should be able to:

✔ Use SELECT to retrieve data


✔ Fetch all or specific columns


✔ Rename columns with aliases


✔ Remove duplicates with DISTINCT


✔ Sort results using ORDER BY


✔ Limit rows depending on DB system


✔ Use basic expressions inside SELECT

SQL Tutorials
What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
SQL Syntax & Statement Types SQL ORDER BY Clause
© 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105