SQL - SELECT, FROM, and WHERE
Table of Contents
This article explains the use of SELECT, FROM, and WHERE for data exploration within SQL.
Also, this article was written with reference to the Inflearn course “Introduction to BigQuery(SQL) for Beginners” by Kyleschool.
SQL Query Structure #
SQL queries are written in the following syntax:
**SELECT**
Col AS new_name,
Col2,
Col3
**FROM** Dataset.Table
**WHERE**
Col1 = 1
-
FROM Dataset.Table: Which table’s data are you inspecting?
-
WHERE: If there are specific conditions you desire, what are they?
Col1 = 1: Conditional statement
-
SELECT: Which columns from the table are you selecting (outputting)?
Col1 AS new_name, Col2, Col3
Example:
SELECT
*
FROM basic.pokemon
WHERE
type1 = “Fire”
***** : Signifies outputting all columns.
SELECT
* EXCEPT (columns to exclude)
→ After specifying columns to exclude and using EXCEPT, it’s also possible to output all columns except the excluded ones.
Description | |
---|---|
FROM | Specifies the table to inspect data from. Alias can be assigned with “AS alias”. e.g. FROM Table1 AS t1 |
WHERE | Filters the data stored in the table specified in FROM (Setting conditions) Conditions are set based on columns in the table |
SELECT | Selects columns stored in the table Multiple columns can be specified Column names can be given aliases with Col1 AS “alias” e.g. SELECT Col1 AS c1 FROM Table 1 AS t1 |
SQL queries are always written in the order of <SELECT - FROM - WHERE>, so it’s essential to remember the sequence.
The sequence <SELECT - WHERE - FROM> is not executable.