We use SELECT all columns to get every piece of information from a table without listing each column name.
SELECT all columns in SQL
Introduction
Syntax
SQL
SELECT * FROM table_name;
The asterisk (*) means 'all columns'.
Replace table_name with the actual name of your table.
Examples
employees table.SQL
SELECT * FROM employees;
SQL
SELECT * FROM orders WHERE order_date = '2024-01-01';
products table.SQL
SELECT * FROM products LIMIT 5;
Sample Program
This creates a simple table called fruits, adds three rows, then selects all columns and rows.
SQL
CREATE TABLE fruits (id INT, name VARCHAR(20), color VARCHAR(20)); INSERT INTO fruits VALUES (1, 'Apple', 'Red'), (2, 'Banana', 'Yellow'), (3, 'Grape', 'Purple'); SELECT * FROM fruits;
Important Notes
Using SELECT * is easy but can be inefficient if the table has many columns and you only need a few.
Always consider listing columns explicitly in large or production queries for better performance and clarity.
Summary
SELECT * fetches all columns from a table.
It is useful for quick checks or when you need every piece of data.
Use it carefully in big tables to avoid slow queries.
Practice
1. What does the SQL query
SELECT * FROM employees; do?easy
Solution
Step 1: Understand the SELECT * syntax
The asterisk (*) means select all columns from the specified table.Step 2: Apply to the employees table
The query fetches every column and every row from the employees table.Final Answer:
It retrieves all columns and all rows from the employees table. -> Option DQuick Check:
SELECT * = all columns and rows [OK]
Hint: SELECT * means get everything from the table [OK]
Common Mistakes:
- Thinking SELECT * deletes or updates data
- Confusing SELECT * with creating tables
- Assuming it selects only one column
2. Which of the following is the correct syntax to select all columns from a table named
products?easy
Solution
Step 1: Recall the correct SELECT syntax
The correct way to select all columns is using SELECT * FROM table_name.Step 2: Check each option
SELECT * FROM products; matches the correct syntax exactly.Final Answer:
SELECT * FROM products; -> Option AQuick Check:
SELECT * FROM table = correct syntax [OK]
Hint: Use SELECT * FROM table_name to get all columns [OK]
Common Mistakes:
- Using SELECT ALL instead of SELECT *
- Forgetting FROM keyword
- Trying to select 'columns' literally
3. Given the table
students with columns id, name, and age, what will the query SELECT * FROM students WHERE age > 20; return?medium
Solution
Step 1: Understand SELECT * with WHERE clause
SELECT * fetches all columns, and WHERE filters rows based on condition.Step 2: Apply condition age > 20
Only rows where age is greater than 20 are returned, with all columns shown.Final Answer:
All columns for students whose age is greater than 20. -> Option CQuick Check:
SELECT * + WHERE filters rows [OK]
Hint: SELECT * returns all columns; WHERE filters rows [OK]
Common Mistakes:
- Thinking WHERE limits columns instead of rows
- Assuming * selects only one column
- Believing * cannot be used with WHERE
4. Identify the error in this SQL query:
SELECT * employees;medium
Solution
Step 1: Check SQL SELECT syntax
The correct syntax requires FROM before the table name.Step 2: Identify missing keyword
The query misses FROM between SELECT * and employees.Final Answer:
Missing FROM keyword before table name. -> Option BQuick Check:
SELECT * FROM table is correct syntax [OK]
Hint: Always use FROM before table name in SELECT [OK]
Common Mistakes:
- Omitting FROM keyword
- Thinking * is invalid
- Adding unnecessary quotes around table name
5. You want to quickly check all data in a large table named
orders. Which query is best to avoid slowing down your database?hard
Solution
Step 1: Understand SELECT * impact on large tables
SELECT * fetches all rows and columns, which can be slow on big tables.Step 2: Use LIMIT to reduce rows fetched
Adding LIMIT 10 fetches only 10 rows, making the query faster and safer.Final Answer:
SELECT * FROM orders LIMIT 10; -> Option AQuick Check:
LIMIT reduces rows, speeding up SELECT * [OK]
Hint: Use LIMIT with SELECT * on big tables to speed queries [OK]
Common Mistakes:
- Running SELECT * without LIMIT on large tables
- Confusing DELETE with SELECT
- Selecting only one column when all data is needed
Recommended
Ready to prove it?
Pass the test and this pattern moves unknown
10 questions ~5 mineasy hard
