Conceito introdutório

~5 min de leitura

SELECT — Retrieving Data

Learn how to query and retrieve data from database tables using the SELECT statement.

Iniciante

What is SELECT?

SELECT is the most fundamental SQL command. It allows you to retrieve data from one or more tables in your database.

Think of it like asking a question to your database: "Show me this information from that table." Every data retrieval operation in SQL starts with SELECT.

Basic Syntax

SELECT column1, column2, ...
FROM table_name;

💡 Pro Tip: SQL keywords like SELECT and FROM are not case-sensitive, but it's common practice to write them in UPPERCASE for readability.

Common Patterns

Use * to retrieve all columns from a table

SELECT * FROM customers;

Result: Returns all columns: id, name, email, country, etc.

See It In Action

Watch how SELECT retrieves and transforms data step by step.

Select Specific Columns

Choose only the columns you need

1

Input Data

customers
idINTEGER
nameTEXT
emailTEXT
countryTEXT
ageINTEGER
1Alice Johnson[email protected]USA28
2Bob Smith[email protected]Canada35
3Carlos Silva[email protected]Brazil22
4Diana Chen[email protected]USA41
5Emma Davis[email protected]Canada19
5 rows displayed
2

SQL Query

SQL
SELECT name, country
FROM customers
3

Result

5 rows
result
nameTEXT
countryTEXT
Alice JohnsonUSA
Bob SmithCanada
Carlos SilvaBrazil
Diana ChenUSA
Emma DavisCanada
5 rows displayed

Key Concepts

*

The Asterisk (*)

Using * selects ALL columns. Great for exploration, but specify columns in production for better performance.

AS

Column Aliases

Use AS to rename columns in your output. Makes results more readable and meaningful.

,

Multiple Columns

Separate column names with commas to select multiple specific columns. Order matters - columns appear in the order you list them.

;

Semicolon

End your SQL statements with a semicolon ;It's required in most databases and is considered best practice.

Common Mistakes to Avoid

❌ Missing FROM clause

SELECT name, email;

You must specify which table to select from!

❌ Missing commas between columns

SELECT name email FROM customers;

Always separate column names with commas!

✅ Correct syntax

SELECT name, email FROM customers;

Perfect! All elements in place.

Pratique a seguirComeçar os desafios →