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

QA Software Testing

  • What is Software testing?
  • Why is Software Testing Necessary? 
  • Top Software Failures Due To Lack Of Testing
  • What is SDLC?
  • What is Waterfall Model?
  • What is Iterative Model?
  • What is Spiral Model?
  • What is V-Model ? (Verification and Validation Model)
  • What is Agile Model ?
  • 7 Software Testing Principles
  • Types of Manual Testing
  • Types of Black Box Testing
  • Types of Functional Testing
  • What is Integration Testing?
  • What is System Testing?
  • What is User Acceptance Testing (UAT)?
  • What is Non-Functional Testing?
  • What is STLC?
  • What is Requirement Analysis? 
  • What is Software Requirements Specification (SRS) ?
  • What is a Business Requirement Document (BRD)?
  • What is Requirement Traceability Matrix (RTM) ? 
  • What is Test Planning Phase?
  • What is Test Case Development  ?
  • What is Test Environment Setup?
  • What is Test Execution Phase in STLC?
  • What is Test Cycle Closure in STLC?
  • What is Software Testing Technique? 
  • Defect vs. Bug in Software Testing
  • Explain defect life cycle using real world example?

Agile

  • What is Agile Methodology?
  • Advantages of Agile Methodology
  • Disadvantages of Agile Methodology
  • Agile Manifesto
  • Twelve Principles of Agile
  • Core Values of Agile
  • History and Evolution of Agile
  • Roles in Agile
  • Artifacts of Agile
  • Product Backlog
  • Sprint Backlog
  • Increment
  • Definition of Done (DoD)
  • Burn-Down Chart
  • Burn-Up Chart
  • Scrum Events
  • Sprint in Scrum
  • Sprint Planning in Scrum
  • Daily Scrum
  • Sprint Review
  • Sprint Retrospective
  • Product Vision and Roadmap
  • Release Planning
  • Sprint Planning
  • Product Backlog
  • Estimation Techniques in Agile
  • Planning Poker
  • T-Shirt Sizes Estimation
  • Fibonacci Sequence Estimation
  • Three-Point Estimation
  • Bucket System Estimation
  • Dot Voting
  • Affinity Estimation
  • What are all the framework available in agile methodology?
  • Scrum Framework
  • Kanban Framework
  • Difference Between Agile and Kanban

API Testing

  • What is an API?
  • Why is API Testing Important?
  • Advantages of API Testing
  • Disadvantages or Challenges of API Testing
  • Differences between API Testing, Unit Testing, and Integration Testing
  • Overview of XML 
  • Overview of JSON
  • Comparison between XML and JSON
  • What are API Methods?
  • What are HTTP Status Codes?
  • What is Web Service Testing?
  • Difference between API and WebService Testing
  • Types of APIs:
  • Request Headers and Parameters
  • Authentication and Authorization
  • API Keys for API Testing
  • OAuth Keys for API Testing
  • JWT (JSON Web Tokens) for API Testing
  • Creating Test Cases for API Functional Testing 
  • Advanced API Testing Techniques
  • Mocking and Stubbing APIs using postman api
  • Contract Testing for APIs
  • Overview of Popular API Testing Frameworks
  • API Testing Best Practices

Java

  • What is Java?
  • Why to Learn Java?
  • History of Java
  • Types of Java Applications
  • Naming Conventions
  • Hello World Program
  • Internal Details of Java program
  • What is Java JDK, JRE and JVM ?
  • What is Java Comments ?
  • What is Java Variable?
  • Variable Naming convention
  • Primitive Data Types
  • Non Primitive Data Types
  • Type Casting
  • Java Arithmetic Operators
  • Relational Operators
  • What is logical operators in Java? 
  • What is Assignment Operators in Java? 
  • What is Unary Operators in Java? 
  • What is Ternary Operators in Java?
  • What is Java Control Statements?
  • What are Decision Making statements?
  • What are looping statements?
  • What are Jump statements?
  • What is OOPS concept in Java?
  • Advantages of Java OOPs
  • What is Java Inheritance?
  • What is Java Constructor?
  • What is this keyword?
  • What is Polymorphism?
  • What is super keyword ?
  • What is final keyword? 
  • What are access modifiers?
  • What is Encapsulation? 
  • What is Abstraction? 

Selenium Automation Testing

  • Introduction to Automation Testing
  • Introduction to Selenium
  • Advantages and Disadvantages of Selenium WebDriver
  • Locators in Selenium
  • How to launch the browsers ? 
  • Browser Navigation Commands in Selenium
  • Handling the textbox and button using selenium
  • Handling the radio button and checkbox using selenium
  • Handling the drop downs and multi-select dropdown
  • Validate the text validation and attributes values. 
  • Handling Images
  • Handling Mouse Events
  • Handling Keyboard Events
  • Handling Alert Popup
  • Handling iFrames
  • Handling Multiple Browsers or Tabs
  • Types of wait statement in selenium
  • How to take screenshots?
  • How to upload File in Selenium?
  • How to handle scroll function using JavaScriptExecutor?
  • How to handle basic functionality using JavaScriptExecutor?
  • How to handle advanced functionality using JavaScriptExecutor?
  • How to automate CAPTCHA?
  • How to handle cookies in selenium

TestNG Framework

  • What is TestNG Framework?
  • Advantages and Disadvantages of TestNG:
  • Difference between TestNG And Junit framework
  • What is TestNG Annotations?
  • Install TestNG In Eclipse & IntelliJ?
  •  Hierarchy In TestNG Annotations
  • TestNG’s prioritization
  • TestNG Dependent
  • Reporter Class in TestNG
  • TestNG Reports
  • Assertions in TestNG
  • TestNG Groups
  • TestNG Parameters
  •  Cross-Browser Testing in TestNG
  •  Parallel Testing in TestNG
  • Data Providers
  • TestNG Listeners
  • Rerunning failed tests in TestNG

Playwright

  • Step-by-Step Node.js Installation on Windows
  • Step-by-Step VS Code Installation on Windows
  • Step-by-Step Playwright Installation on Windows
  • Playwright VS Code extension Installation and Execution
  • Playwright Folder Structure
  • Playwright Core Concepts
  • First Playwright Program
  • Validate Page Title and URL
  • Handle Browser Navigation
  • Playwright Built-in Locators
  • Locators in Playwright CSS Selector vs XPath

Manual Testing Interview Question

  • Manual Testing Interview Questions and Answers For Freshers
  • Manual Testing Interview Questions and Answers For Experienced

Agile Interview Questions and Answers

  • Agile Interview Questions and Answers for freshers
  • Agile Scenario Based Interview Questions and Answers

Cypress Interview Questions and Answers

  • Cypress Interview Questions and Answers

Git Github Interview Questions and Answers

  • Git Github Interview Questions and Answers

Jenkins Interview Questions and Answers

  • Jenkins Interview Questions and Answers

Java Basic Programs

  • Basics Java Programs

Python Programming

  • Simple Python Programs for Beginners

General Interview Questions and Answers

  • Why are you interested for this position?
  • What do you know about our company?
  • Why do you want to work here?
  • What are your strengths?
  • What are your weaknesses?
  • Can you describe a challenge you’ve faced at work and how you dealt with it?
  • Why should we hire you?
  • Where do you see yourself in five years?
  • Why are you leaving your current job?
  • Tell me about yourself

Behavioral Interview Questions and Answers

  • Describe a time when you had to work under pressure.
  • Give an example of a goal you reached and how you achieved it.
  • Tell me about a time you made a mistake. How did you handle it?
  • Describe a time when you worked as part of a team.
  • Give an example of a time you showed initiative.
  • Tell me about a time when you had a conflict at work. How did you handle it?
  • Describe a situation where you had to meet a tight deadline.
  • Tell me about a time you had to learn something new quickly.
  • Describe a time when you had to deal with a difficult customer.
  • Give an example of how you have demonstrated leadership in the past.

Situational Interview Questions and Answers

  • What would you do if you disagreed with a decision made by your boss?
  • How would you handle a situation where you had multiple high-priority tasks due at the same time?
  • What would you do if you saw a colleague acting unethically?
  • How would you handle a situation where you had to give negative feedback to a team member?
  • What steps would you take if you were assigned a project outside your expertise?
  • How would you approach a task you’ve never done before?
  • What would you do if you noticed a significant drop in your team’s performance?
  • How would you handle a situation where a project’s requirements changed midway?
  • What would you do if you were asked to complete a task that you felt was unethical or illegal?
  • How would you handle a situation where you had to meet a critical deadline but lacked the necessary resources?

Questions About Company Fit

  • What kind of work environment do you thrive in?
  • How do you handle feedback?
  • Describe your ideal manager or supervisor.
  • What motivates you to do your best work?
  • How do you handle stress and pressure?
  • How do you balance work and personal life?
  • What are your hobbies and interests outside of work?
  • How do you stay organized?
  • What is your approach to teamwork and collaboration?
  • How do you handle ambiguity and change?

Closing Interview Questions and Answers

  • Do you have any questions for us?
  • What are your salary expectations?
  • When can you start?
  • Are you considering other job offers?
  • Is there anything else you’d like us to know about you?
  • How do you handle failure?
  • What is your proudest professional achievement?
  • How do you ensure you maintain high standards in your work?
  • What are your professional development goals?
  • How do you stay motivated in your job?

SQL Tutorials

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

SQL ORDER BY Clause

SQL ORDER BY Clause

The ORDER BY clause is used to sort the rows returned by a SELECT query.
By default, SQL returns data in no guaranteed order, so if you want organised results — alphabetical, numeric, highest to lowest, earliest to latest — you must use ORDER BY.

This tutorial explains how to sort data using one or multiple columns in both ascending and descending order.

1. Basic Syntax of ORDER BY

🗃️
SELECT column1, column2, ...

FROM table_name

ORDER BY column1 [ASC|DESC], column2 [ASC|DESC], ...;

ASC → Ascending order (default)

DESC → Descending order

You can sort by one or many columns

Numeric, text, date, and expression columns can all be sorted

2. Sorting by One Column

🗃️
-- Example: Sort employees by their first name:

SELECT FirstName, LastName, Salary

FROM Employees

ORDER BY FirstName;

-- Because ascending order is default, the result is A → Z.

-- To reverse the order:

SELECT FirstName, LastName, Salary

FROM Employees

ORDER BY FirstName DESC;

3. Sorting by Multiple Columns

When two or more rows have the same value in the first column, SQL uses the next column to break the tie.

🗃️
-- Example:

SELECT FirstName, LastName, City

FROM Employees

ORDER BY City ASC, LastName ASC;

Meaning:

  • Sort by City first
  • If two people live in the same city → sort by LastName

🗃️
-- Another example (common in banking/salary data):

SELECT Department, Salary, FirstName

FROM Employees

ORDER BY Department ASC, Salary DESC;

4. Sorting by an Expression

You can sort by a calculated column, even if it’s not shown in the result.

🗃️
-- Example: Sort employees by annual salary (calculated on the fly):

SELECT 

    FirstName,

    Salary,

    Salary * 12 AS AnnualSalary

-- FROM Employees

ORDER BY Salary * 12 DESC;

-- Or sort by length of employee names:

SELECT FirstName, LastName

FROM Employees

ORDER BY LENGTH(FirstName);

5. Sorting by Column Position (Not Recommended Usually)

SQL allows sorting using the column number in the SELECT list:

🗃️
SELECT FirstName, LastName, Salary

FROM Employees

ORDER BY 3 DESC;

Here, 3 means the third column in the SELECT list → Salary.

Although allowed, this is not recommended because:

  • Harder to read
  • Risky when someone changes the SELECT column order later

Use column names for clarity.

6. ORDER BY with NULL Values

SQL does not treat NULL as a normal value.
Sorting behaviour:

  • In ASC, NULL appears first in most databases

  • In DESC, NULL appears last

🗃️
-- Example:

SELECT FirstName, Bonus

FROM Employees

ORDER BY Bonus ASC;

-- To explicitly control placement:

-- NULLS LAST (PostgreSQL, Oracle):

SELECT FirstName, Bonus

FROM Employees

ORDER BY Bonus ASC NULLS LAST;

-- NULLS FIRST (PostgreSQL, Oracle):

ORDER BY Bonus DESC NULLS FIRST;

(MySQL doesn’t support NULLS FIRST/LAST, but you can simulate it with conditions.)

7. ORDER BY with Aliases

You can sort using the alias defined in the SELECT clause.

🗃️
SELECT

    FirstName,

    LastName,

    Salary * 12 AS AnnualSalary

FROM Employees

ORDER BY AnnualSalary DESC;

This improves readability, especially with complex calculations.

8. ORDER BY with LIMIT / TOP / FETCH

Sorting is usually combined with row-limiting clauses.

🗃️
-- MySQL / PostgreSQL:

SELECT *

FROM Employees

ORDER BY Salary DESC

LIMIT 5;

-- SQL Server:

SELECT TOP 5 *

FROM Employees

ORDER BY Salary DESC;

-- Standard SQL:

SELECT *

FROM Employees

ORDER BY Salary DESC

FETCH FIRST 5 ROWS ONLY;

9. Practical Example (Real-World Scenario)

Imagine a Transactions table:

TxnIDCustomerIDAmountTxnDateType
1012001350.002025-11-14Credit
1022001120.002025-11-13Debit
1032002900.002025-11-14Credit
1042003NULL2025-11-12Refund
🗃️
-- Sort by latest transactions:

SELECT TxnID, CustomerID, Amount, TxnDate

FROM Transactions

ORDER BY TxnDate DESC;

-- Sort by amount (biggest first), NULL amounts last:

SELECT TxnID, Amount, TxnDate

FROM Transactions

ORDER BY Amount DESC NULLS LAST;

-- Sort by type and then by date:

SELECT TxnID, Type, Amount, TxnDate

FROM Transactions

ORDER BY Type ASC, TxnDate DESC;

10. Summary

By now you should understand:

✔ How to sort rows using ORDER BY


✔ Difference between ASC and DESC


✔ Sorting with multiple columns


✔ Sorting by expressions and aliases


✔ Handling NULLs in sorting


✔ How ORDER BY works with LIMIT/TOP

The ORDER BY clause is one of the most important tools for analysing and presenting data accurately.

What are your Feelings

Share This Article :

  • Facebook
  • X
  • LinkedIn
SQL SELECT Statement
© 2025 V-Tech Solutions Ltd (UK), Reg. No: 16489105