GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • SQL
  • Projects
  • Interview Questions
  • Quiz
  • DBMS
  • PostgreSQL
  • Django
  • ReactJS
  • Vue.js
  • AngularJS
  • API
  • REST API
  • SQL3 min read
  • Data Types3 min read

This view

  • Original page
  • New address

GeezerVison is showing www.geeksforgeeks.org — SQL SELECT Query (With Examples) - GeeksforGeeks

geeksforgeeks
search icon
  • Courses
  • Tutorials
  • Interview Prep
  • SQL
  • Projects
  • Interview Questions
  • Quiz
  • DBMS
  • PostgreSQL
  • Django
  • ReactJS
  • Vue.js
  • AngularJS
  • API
  • REST API

SQL SELECT Query

Last Updated : 21 Aug, 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-08-20-100823
customers

Query:

SELECT customers_id, first_name
FROM customers;

Output:

Screenshot-2026-08-20-101022

Syntax

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

Working

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 customerss table. Here we will fetch only first_name and last_name for each record.

Query:

SELECT first_name, last_name 
FROM customers;

Output:

Screenshot-2026-08-20-102457

Example 2: Select All Columns

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

Query:

 SELECT * FROM customers;

Output:

Screenshot-2026-08-20-100823

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 first_name
FROM customers
WHERE age = 21;

Output:

Screenshot-2026-08-20-102656

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 customers
GROUP BY country;

Output:

Screenshot-2026-08-20-102715

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 customers table.

Query:

SELECT DISTINCT country
FROM customers;

Output:

Screenshot-2026-08-20-102731

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 customers table.

Query:

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

Output:

Screenshot-2026-08-20-102759

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 customers
ORDER BY age DESC;

Output:

Screenshot-2026-08-20-102838

Example 8: SELECT Statement with LIMIT clause

In this example, we will use SELECT Statement with LIMIT clause

Query:

SELECT * FROM customers
LIMIT 3;

Output:

Screenshot-2026-08-20-104558
Comment

Explore

    Basics
    • SQL3 min read
    • Data Types3 min read
    • Operators4 min read
    • Commands5 min read
    • Database Operations2 min read
    • CREATE TABLE2 min read
    Queries & Operations
    • SELECT Query2 min read
    • INSERT INTO3 min read
    • UPDATE2 min read
    • DELETE2 min read
    • WHERE2 min read
    • Aliases2 min read
    Joins & Functions
    • Joins3 min read
    • CROSS JOIN1 min read
    • Date Functions2 min read
    • String functions4 min read
    Data Constraints & Aggregate Functions
    • NOT NULL Constraint3 min read
    • PRIMARY KEY3 min read
    • Count()4 min read
    • SUM()2 min read
    • MAX()3 min read
    • AVG()2 min read
    Advanced SQL Topics
    • Subquery4 min read
    • Window Functions4 min read
    • Stored Procedures3 min read
    • Triggers4 min read
    • Performance Tuning4 min read
    • TRANSACTIONS4 min read
    Database Design & Security
    • ER Model9 min read
    • Normalization2 min read
    • Keys in Relational Model7 min read
    • SQL Injection10 min read
    • Data Encryption3 min read
    • SQL Backup4 min read
    • ORM in DBMS5 min read
    Courses
    • Placement 360 Course2 min read
    • Data Science 360 Course2 min read
    • MERN Full Stack Course2 min read
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.