Today, DS41 and myself got our first introduction into Structured Query Language (SQL). SQL is a coding language used to communicate and query relational databases.
There are a variety of different vendors of the language, including Microsoft SQL Server, Oracle SQL, and Snowflake SQL, to name just a few. We focused our attention on Snowflake SQL.
Using SQL we can:
1.) Execute queries to retrieve data from a database.
2.) Insert, update, and delete data.
3.) Create new databases, tables, views, and stored procedures.
4.) Set permissions.
There is some basic terminology we need to get our heads around in order to create a query statement within SQL, and we must use these terms in the correct order.
1.) SELECT
- The select statement is used to retrieve data from one or more tables. You specify the columns you want to retrieve data from, and you can also use functions to manipulate the data. eg. 'select *' (where * means all)
2.) FROM
- The from statement specifies the table or tables from which you want to retrieve data. This clause is a required part of the query because you must specify the source of the data. e.g 'from orders' (where orders is the orders table)
3.) WHERE
- The where statement is used to filter the rows retrieved from the table based on a specified condition. It allows you to specify criteria that must be met for a row to be included in the results. e.g. 'where sales between 50 and 100'
4.) GROUP BY
- The group by statement is used to group rows of data that have the same values in one or more columns into summary rows. e.g. 'group by department'
5.) HAVING
- The having statement is used in combination with the group by statement to filter the grouped rows based on conditions. It's similar to the where statement but operates on the result set after grouping. e.g. 'having sum(sales) > 100'
6.) ORDER BY
- The ORDER BY
clause is used to sort the result set in ascending or descending order based on one or more columns. You can specify which columns to sort by and the sort direction. e.g. 'order by order_date DESC'
I hope this blog has been useful in outlining some of the SQL basics. I'm really excited to keep learning and practicing Snowflake SQL!