↓ Skip to main content
  1. Courses/
  2. SQL/

Select, From, Where

·377 words·2 mins· loading · loading ·
Russell Chubb
Author
Russell Chubb
Working at the intersection of Technology and Art.
Learn SQL - This article is part of a series.
Part 1: This Article

Video 📹
#

SELECT and FROM
#

The SELECT statement is used to fetch data from a database and is one of the most fundamental building blocks of SQL queries. The FROM statement specifies the exact table and database target from which to retrieve that data.

Note

SQL statement execution order is strict. A query must define what to fetch (SELECT) and where to fetch it from (FROM) before applying filters.

SELECT and FROM Syntax
#

To return all columns from a table, use the asterisk (*) wildcard:

SELECT * 
FROM table_name;

To specify individual columns rather than fetching the entire dataset:

SELECT column1, column2, ...
FROM table_name;

Demo Database
#

Below is a selection from a made-up People table (from Russell’s Surf Store Database):

PersonIDNameAgeCity
1Oscar Macdonald25Brighton
2Kian Knight25Munich
3Jock Adams25Sydney
4Liam Barnes25Vancouver
5Jake Faville24Cork

WHERE
#

The WHERE clause is used to filter records so that only rows meeting specific criteria are returned.

WHERE Syntax
#

SELECT column1, column2, ...
FROM table_name
WHERE condition;

SQL WHERE Example
#

The following SQL returns only the names and ages of people older than 30:

-- Example
SELECT Name, Age
FROM my_dataset.my_table
WHERE Age > 30;

Query Rules & Best Practices
#

1. Clause Order
#

Statements must follow a strict order (SELECT → FROM → WHERE). Placing clauses out of sequence will result in a syntax error:

-- Incorrect Query (Will not execute):
WHERE Age > 30;
SELECT Name, Age
FROM my_dataset.my_table

2. Case Sensitivity
#

SQL keywords are generally case-insensitive, meaning the following queries produce identical results:

-- Uppercase (Recommended)
SELECT Name, Age
FROM my_dataset.my_table
WHERE Age > 30;

-- Lowercase
select Name, Age
from my_dataset.my_table
where Age > 30;
Note

While keywords are case-insensitive, string literals (e.g., 'John') or database object names may be case-sensitive depending on the database engine.

3. Readability & Performance
#

  • Keywords vs. Identifiers: Write keywords in UPPERCASE and column/table names in lowercase or PascalCase.
  • Line Breaks: Avoid running long queries on a single line. Break statements onto new lines for legibility.
  • Avoid SELECT * in Production: Explicitly state column names instead of using * to optimize performance and reduce unnecessary query bandwidth.
Learn SQL - This article is part of a series.
Part 1: This Article

Related

Group By, Order By

547 words·3 mins· loading · loading
Introduction to the Group By, Order By parameters in SQL

My Gym Split

512 words·3 mins· loading · loading
Want to learn how I’ve grown my mid-physique? - Check out this post…

Classes

562 words·3 mins· loading · loading
Classes in Python