▶ Try SQL

SQL SELECT Statement

The SELECT statement is used to fetch data from a database table.

The SELECT Statement

The SELECT statement is the most common SQL statement. It retrieves rows from one or more tables.

Syntax

Syntax
SELECT column1, column2, ... FROM table_name;

Select All Columns

Use * to select all columns from a table:

Example — Select all
SELECT * FROM customers;

Select Specific Columns

Name the columns you want to retrieve:

Example — Specific columns
SELECT name, city FROM customers;

SELECT DISTINCT

The SELECT DISTINCT statement returns only unique (different) values:

Example — Distinct countries
SELECT DISTINCT country FROM customers;

Column Aliases with AS

Use AS to give a column a temporary, readable name in the result:

Example — Column alias
SELECT name AS customer_name, city AS location FROM customers;
✅ Best Practice Always specify the columns you need rather than using SELECT * in production queries. It makes your code clearer and faster.