SQL SELECT, WHERE and ORDER BY Commands – Learn SQL Basics with Examples
Database

SQL SELECT, WHERE and ORDER BY Commands – Learn SQL Basics with Examples

22 Sep, 2026 CCI Admin Database
Back to All Blogs

SQL SELECT, WHERE and ORDER BY Commands – Learn SQL Basics with Examples

Published: 22 Sep, 2026 | Author: CCI Admin | Category: SQL / Database

SQL (Structured Query Language) is used to store, retrieve, update, and manage data in relational databases. Among the most commonly used SQL commands are SELECT, WHERE, and ORDER BY. These commands help us retrieve the required data, filter records, and sort results.

What is the SQL SELECT Command?

The SELECT command is used to retrieve data from one or more tables in a database. It is one of the most frequently used SQL commands.

Basic Syntax

SELECT column_name
FROM table_name;

Example

Suppose we have a table named students:

id name course marks
1 Arun Python 85
2 Priya Java 92
3 Karthik SQL 78

To display all columns:

SELECT * FROM students;

To display only student names and marks:

SELECT name, marks
FROM students;

What is the SQL WHERE Command?

The WHERE clause is used to filter records based on a specific condition. It helps us retrieve only the rows that match the given condition.

Basic Syntax

SELECT column_name
FROM table_name
WHERE condition;

Example

To find students who scored more than 80 marks:

SELECT * 
FROM students
WHERE marks > 80;

This query displays only the students whose marks are greater than 80.

WHERE with Text Values

We can also use WHERE to search for a particular course.

SELECT *
FROM students
WHERE course = 'Python';

Common WHERE Operators

Operator Meaning Example
= Equal to marks = 80
> Greater than marks > 80
< Less than marks < 80
>= Greater than or equal to marks >= 80
<= Less than or equal to marks <= 80
<> Not equal to marks <> 80

What is the SQL ORDER BY Command?

The ORDER BY clause is used to sort the result of a query. By default, SQL sorts values in ascending order.

Basic Syntax

SELECT column_name
FROM table_name
ORDER BY column_name;

Example – Ascending Order

To display students from the lowest marks to the highest marks:

SELECT *
FROM students
ORDER BY marks ASC;

Example – Descending Order

To display students from the highest marks to the lowest marks:

SELECT *
FROM students
ORDER BY marks DESC;

ASC means ascending order, while DESC means descending order.

Using SELECT, WHERE and ORDER BY Together

These commands can be combined to create useful database queries. For example, suppose we want to display students who scored more than 80 marks, sorted from highest to lowest.

SELECT name, marks
FROM students
WHERE marks > 80
ORDER BY marks DESC;

This query first selects the required columns, then filters students with marks above 80, and finally sorts the result in descending order.

Real-Time Example

Imagine a college database containing student information. A teacher may want to find all students who scored more than 75 marks and display them from the highest score to the lowest score.

SELECT name, course, marks
FROM students
WHERE marks > 75
ORDER BY marks DESC;

This type of query is useful in student management systems, examination systems, employee databases, sales applications, and many other real-world applications.

Quick Difference

Command Purpose Example
SELECT Retrieves data SELECT * FROM students;
WHERE Filters data WHERE marks > 80
ORDER BY Sorts data ORDER BY marks DESC

Why Learn These SQL Commands?

  • They are fundamental SQL commands for beginners.
  • They help retrieve specific information from databases.
  • They are useful in real-world applications.
  • They are commonly used in database-driven websites and software.
  • They provide a strong foundation for learning advanced SQL.

Frequently Asked Questions

1. What is SELECT in SQL?

SELECT is used to retrieve data from a database table.

2. What is WHERE used for?

WHERE is used to filter records according to a specified condition.

3. What is ORDER BY in SQL?

ORDER BY is used to sort query results in ascending or descending order.

4. Can SELECT, WHERE and ORDER BY be used together?

Yes. They can be combined to retrieve, filter, and sort database records in a single query.

Conclusion

SQL SELECT, WHERE, and ORDER BY are essential commands for anyone starting with databases. SELECT retrieves data, WHERE filters the required records, and ORDER BY sorts the results. Practicing these commands with simple tables is a great way to build a strong foundation in SQL.

At CCI Computer Education, Pudukkottai, students can learn SQL and other programming and computer technologies through practical examples and projects.

Related CCI Blogs


Contact CCI Computer Education – Pudukkottai

Want to learn JavaScript, Web Development, and other programming skills through practical training?

Call: 98427 97945  |  Website: ccipudukkottai.com

WhatsApp Channel: Join Now

Share: Facebook | WhatsApp | Twitter