SQL SELECT Statement

The SELECT statement in SQL is the fundamental command for retrieving data from a database. It's how you get information out of your tables.



SELECT: Definition and Usage

SELECT lets you choose specific columns or all columns from one or more tables. The results are organized into a result set—a table containing the selected data. You can use a WHERE clause to filter the results and an ORDER BY clause to sort them.

Syntax

Syntax

SELECT column1, column2,...
FROM table_name;
      

Replace column1, column2,... with the names of the columns you want, or use * to select all columns.

Examples

Selecting Specific Columns

This example retrieves only the 'CustomerName' and 'City' columns from the 'Customers' table. (This assumes a 'Customers' table exists with those columns.)

Syntax

SELECT CustomerName, City FROM Customers;
      
Output

CustomerName | City
--------------------
(Customer names and cities will be displayed here)
      

Selecting All Columns

This example retrieves all columns from the 'Customers' table.

Syntax

SELECT * FROM Customers;
      
Output

(All columns and rows from the Customers table will be displayed here.)
      

**Note:** The example outputs assume the existence of a `Customers` table. The specific data in the output will depend on the contents of your `Customers` table. If the table is empty, the output will be an empty table.