Course contentsShow
← Data Science
Lesson 851 of 2,14522. SQL FoundationsFree lesson

Selecting All Columns with Asterisk

Use SELECT * to retrieve all columns from a table and understand when this approach is appropriate versus explicit column selection.

Selecting All Columns with Asterisk

You'll learn how to use the asterisk (*) wildcard to retrieve every column from a table in one quick command.

What Does SELECT * Do?

When you write SELECT * in SQL, the asterisk acts as a shorthand that means "give me all columns." Instead of typing out each column name individually, the * wildcard automatically retrieves every column in the table you specify in the FROM clause.

Think of it like ordering "one of everything" at a restaurant rather than naming each dish individually—faster to say, but you get the whole menu.

The Basic Syntax

SELECT *
FROM employees;

This query returns all columns from the employees table. If the table has 5 columns or 50 columns, you'll get them all in your result set.

When to Use SELECT *

The asterisk is appropriate when:

  • Exploring data: You're getting familiar with a new table and want to see what's in it
  • Small tables: The table has few columns and you genuinely need all of them
  • Quick ad-hoc queries: You're doing temporary analysis and speed matters more than precision

When to Avoid SELECT *

Explicitly naming columns is better when:

  • Production code: Applications should specify exactly which columns they need for clarity and performance
  • Large tables: Retrieving unnecessary columns wastes bandwidth and memory
  • Joining tables: Multiple tables might have overlapping column names, causing confusion

Key Takeaway: SELECT * is a convenient shortcut for retrieving all columns, ideal for exploration but typically avoided in production code where explicit column selection is clearer and more efficient.