First, let's select data for the queries. I'll go with my Coffee Quality repo, the data is from @KaggleDatasets, you can access it there.
Now, back to Chapter.
This chapter is basically about #MySQL statements. It covers select, from, where, group by, order by and having.
2⃣ But first, it would be better to understand how SQL Server executes your queries. When we run a query, the server checks 3 things:
▶️ Permission to execute query
▶️ Permission to access database
▶️ Statement syntax
3⃣ If the query passes all, that it handed the 'query optimizer', whose job is to determine the most efficient way to execute the query.
❗️This doesn't mean, your query is the best. You still need to think of queries that will perform better. Read 'High Performance SQL'
4⃣ Let's talk about SQL Query Clauses;
▶️ SELECT -> determines which columns to show
▶️ FROM -> identifies the table
▶️ WHERE -> filtering
▶️ GROUP BY -> group rows by column value
▶️ HAVING -> filtering, again !!
▶️ ORDER BY -> sorting
5⃣ Select and Alias
Select is one of the last statements that server runs. cause before selecting what to include, it needs to know what are the possible columns. Here are some examples
6⃣ Removing duplicates - DISTINCT
Returns with no repetitions of the selected column
7⃣ FROM - is an easy one, right? However, we should be aware of table types while using from.
There are 4 types of tables: 1. Permanent (CREATE TABLE) 2. Derived - a subquery-generated table 3. Temporary - only available at the current session 4. Virtual (views) - ...
7⃣.a
How to create a temporary table
DROP TABLE is good for if you want to create the table by trial and error, or you want to change it by time.
7⃣.b
How to create a VIEW, and why?
In advanced DB's to hide some columns from users, to simplify DB design, create a summary for users, for faster results
8⃣ ALIASes for Multiple tables
When joining 2 or more tables, we need to create aliases for each table to avoid duplicate columns and errors.
We can do it by simply writing AS or without AS, just like in the example.
9⃣ WHERE and HAVING
They are doing same job, right? Filtering. However, their intentions are not the same. We can use WHERE before or without group by statement while HAVING is used for filtering grouped data.
🔟 ORDER BY
Another easy statement, you should write at the end of the query.
Additionally you can add at the end DESC or ASC for ascending or descending order.
🔚 Well, in chapter three we made an introduction to MySQL. Hope you will find this helpful.
2⃣ #MySQL Datatypes 1. Character data:
☑️ Fixed-length : right-pinned with spaces
☑️ Variable length : not padded, space consumption varies
i.e : char(20) - fixed ; varchar(20) variable length examples.
3⃣ Character Sets are used for different languages with different letters
Returns a table with different char sets. If maxlen bigger than 1, the chars in that language are bigger than 1 bytes.
A quick note before starting, check @levikul09 for statistics and python related information.
These tweets are my notes from @OReillyMedia#LearningSQL book chapter 1. All the credit goes to that book.
2⃣What is a database? Why it is important in data world?
Well this is easy to answer, there are nearly 2.5 quintillion bytes of data created every day. So it is crucial that this data stored in someplace. That place is called a Database, a set of related information.
2
3⃣Today we are using Relational Database model most of the time. Before, there were Non-Relational Systems:
☑️Hierarchical Database Systems - same as Decision Trees
☑️Network Database Systems - sets of records and sets of link that defines the relationship