SQL - select all columns from a selected set of rows

In SQL, if you want to select all columns from a selected set of rows, you use the SELECT * statement along with a WHERE clause.

Syntax:

SELECT * FROM table_name
WHERE condition;

Explanation:

  • SELECT * → means select all columns from the table.

  • FROM table_name → specifies the table to select data from.

  • WHERE condition → filters the rows, selecting only those that meet the condition.

Example:

Consider a table named employees:

id name department salary
1 Alice HR 50000
2 Bob IT 60000
3 Carol IT 65000

If you want to select all columns for employees in the IT department, you would write:

SELECT * FROM employees
WHERE department = 'IT';

Result:

id name department salary
2 Bob IT 60000
3 Carol IT 65000

This is how you select all columns but only certain rows based on a condition.