The SELECT statement in SQL is used to query and retrieve data from one or more tables in a database. It is one of the most fundamental and widely used commands in SQL. Below is a comprehensive overview of the SELECT statement, including its syntax, various clauses, and examples of how to use it.

Basic Syntax

The basic syntax of the SELECT statement is as follows:

SELECT column1, column2, ...
FROM table_name
WHERE condition;

Components of the SELECT Statement

  1. SELECT : Specifies the columns to be retrieved.
  2. FROM : Indicates the table from which to retrieve the data.
  3. WHERE : (Optional) Filters records based on specified conditions.

Examples of Using SELECT

1. Selecting All Columns

To select all columns from a table, use the asterisk (*):

SELECT * FROM table_name;

Example:

SELECT * FROM cats;

2. Selecting Specific Columns

To select specific columns, list them after the SELECT keyword:

SELECT column1, column2 FROM table_name;

Example: