Tomorrow, we have our first official SQL training at the Data School. Therefore, I thought it would be good practice for me to write a blog introducing the basics of Structured Query Language (SQL) as a refresher. There are a few types of SQL from PostgresSQL, MySQL, Oracle etc.
Before I became a Data Analyst, I looked at job postings and blogs, and subreddits, and a theme began to emerge. SQL seemed to be pretty important. I took a course and passed the SQL Fundamentals via Datacamp and managed to grasp most of the concepts. It is not that complicated really.
The Foundations
All SQL queries follow roughly the same structure at their base.
SELECT FROM
Select is what you want and from is where you want it from.
Example:
SELECT * FROM `bigquery-public-data.new_york_trees.tree_species`
This returns all the fields from the selected database about trees species in New York. The ” * ” represents the wildcard ‘all’.

If I only want to return certain fields I would include them in my SELECT statement.
SELECT species_common_name,fall_color, tree_size FROM `bigquery-public-data.new_york_trees.tree_species`

WHERE?
The WHERE command is when we start to filter data from the database table.
e.g.
SELECT species_common_name,fall_color, tree_size FROM `bigquery-public-data.new_york_trees.tree_species` WHERE tree_size= 'Large (Mature Height > 50 ft)'
SELECT species_common_name,fall_color, tree_size FROM `bigquery-public-data.new_york_trees.tree_species` WHERE tree_size= 'Large (Mature Height > 50 ft)' AND fall_color= 'Yellow'

SELECT species_common_name,fall_color, tree_size FROM `bigquery-public-data.new_york_trees.tree_species` WHERE NOT tree_size= 'Large (Mature Height > 50 ft)' AND fall_color= 'Yellow'

GROUP BY, ORDER BY –
SELECT COUNT(fall_color), species_common_name FROM `bigquery-public-data.new_york_trees.tree_species` GROUP BY species_common_name
SELECT species_common_name FROM `bigquery-public-data.new_york_trees.tree_species` ORDER BY species_common_name desc

HAVING
This is used when there are aggregate functions and can’t use the WHERE clause anymore due to the row-by-row nature of the WHERE filters.
SELECT COUNT(growth_rate), growth_rate FROM `bigquery-public-data.new_york_trees.tree_species` GROUP BY growth_rate HAVING COUNT(growth_rate)>20