SQL SELECT Query

Last Updated : 13 Jan, 2026

The SQL SELECT statement is used to retrieve data from one or more tables and display it in a structured format of rows and columns.

  • Fetches all columns using * or specific columns by name.
  • Filters and sorts data using WHERE and ORDER BY.
  • Supports grouping, aggregation, and table relationships using GROUP BY, HAVING, and JOIN.

Example: First, we create a demo SQL table, on which we use the SELECT query.

Screenshot-2026-01-13-112918
Customer Table

Query:

SELECT CustomerID, FirstName FROM Customer;

Output:

Screenshot-2026-01-13-113122

Syntax:

SELECT column1,column2.... FROM table_name;
  • column1, column2: columns you want to retrieve.
  • table_name: name of the table you're querying.

Working with the SELECT Statement

The SELECT statement is used to retrieve and display data from one or more tables in a structured and readable format.

Example 1: Select Specific Columns

In this example, we will demonstrate how to retrieve specific columns from the Customer table. Here we will fetch only CustomerName and LastName for each record.

Query:

SELECT FirstName, LastName 
FROM Customer;

Output:

Screenshot-2026-01-13-115323

Example 2: Select All Columns

In this example, we will fetch all the fields from table Customer:

Query:

 SELECT * FROM Customer;

Output:

Screenshot-2026-01-13-112918

Example 3: SELECT Statement with WHERE Clause

Suppose we want to see table values with specific conditions then WHERE Clause is used with select statement. In this example, filter customers who are 21 years old.

Query:

SELECT FirstName 
FROM Customer
where Age = 21;

Output:

Screenshot-2026-01-13-115411

Example 4: SELECT with GROUP BY Clause

In this example, we will use SELECT statement with GROUP BY Clause to group rows and perform aggregation. Here, we will count the number of customers from each country.

Query:

SELECT Country, COUNT(*) AS customer_count
FROM Customer
GROUP BY Country;

Output:

Screenshot-2026-01-13-115441

Example 5: SELECT with DISTINCT Clause

In this example, we will use DISTINCT keyword to return only unique values from a column. Here, we will fetch unique countries from the Customer table.

Query:

SELECT DISTINCT Country
FROM Customer;

Output:

Screenshot-2026-01-13-115504

Example 6: SELECT Statement with HAVING Clause

The HAVING clause is used to filter results after applying GROUP BY. In this example, we will find countries that have 2 or more customers in the Customer table.

Query:

SELECT Country, COUNT(*) AS customer_count
FROM Customer
GROUP BY Country
HAVING COUNT(*) >= 2;

Output:

Screenshot-2026-01-13-115522

Example 7: SELECT Statement with ORDER BY clause

In this example, we will use SELECT Statement with ORDER BY clause. Here, Sort results by Age in descending order.

Query:

SELECT * FROM Customer ORDER BY Age DESC;   

Output:

Screenshot-2026-01-13-115545
Suggested Quiz

0 Questions

Quiz Completed Successfully

Your Score : 0/0

Accuracy : 0%

Comment