SQL is a very organized, functional but tricky language. It is tricky because you have to logically think about which things or variables need to be factored in in order to smartly obtain important data from a table/database. I learnt a lot in one of my projects about handling some of the functions used in SQL and how they are used so that we can query a dataset with relevant data. It does get tricky, lets see some other commands used in this very interesting language: JOINS!There are some basic commands in SQL about having to retrieve only some number of cols of the table, or the entire table, or just some records (or rows) of the table, and these commands are: SELECT, FROM, WHERE, HAVING, ORDER BY. But what if you have more than one table? And you want to find out what the relationship between these two table's are? For example, lets say you have two tables: the customers table and a person table. If you want to filter out the commonalities between these two tables (which records consist of the same individual, for example), you could use Joins. If two tables had a common column or variable, you can merge these two tables together to gather valuable information. So the table to the left is the Customers database, and the table to the right represents the Persons database. Lets say the problem was to find out which individuals have been a customer to a particular store. How would you go about solving this? The common column or key between this two tables is the 'CustomerID'/'PersonID' column. We can use this column to essentially 'match' the tables, and collect valuable info as to the people who have shopped in a particular store. So to query the common keys between the tables is to use the "INNER JOIN" command. The INNER JOIN outputs the common records which share the same ID/key value between two or more tables. So using the INNER JOIN command here would give you: Querying the data
The Inner Join deals with finding the common keys between tables, but there are many many more JOIN types! (Such as Left Join, Right Join, Self Joins, Anti Join, Semi Join..etc. It is absolutely an endless but exciting world of SQL.
0 Comments
|
Archives
December 2020
Topics
All
|