Listen to Your Favourite Programming Podcasts and Books on Audible - Here is a Free Trial - Click Here - Offer Limited Time Only
SQL Joins in 2 Minutes

SQL Joins in 2 Minutes

Marty Jacobs · Mar 29, 2019 17:55 · 341 words · 2 minute read

Alt Text!

What is an SQL Join? It is a Structured Query Language (SQL) clause used to combine data from two different database tables. Through combining the tables, there is more data to draw conclusions from. This means that it’s possible to find answers to more complicated questions when querying your dataset.

For example, if we want to query a hotel database to find out how many transactions a guest has made inside the hotel, we can perform a JOIN on the guest table and the transactions table. Once we have a combined table, we can query the “guest number” or guest_id to find out the number of transactions.

Let’s take a look at what this might look like when programming the SQL query:

select number_of_transactions
from guests
join transactions
   on guests.guest_id = transactions.guest_id
where guest_id = 2000

The above code returns the number of transactions from the guest inside the hotel. This is done by joining on the primary key “guest_id” between the two tables, setting the where condition (guest id = 2000) and then selecting the number_of_transactions field.

SQL Joins are very powerful in finding out information. They are often used in the field of Data Science, Software development, and can be used to gather Business Intelligence (BI). There a various types of joins which combine your data in different ways. W3Schools do a fantastic job at showing the different types of JOINS, providing examples to get your hands dirty while learning.

Remember, SQL can be only used to manipulate data inside a Relational Database Management Systems (RDBMS). The JOIN clause is unavailable if you are using an object database to hold your data. MySQL is a great choice when selecting a relational database, as it is trusted and used by major companies, Facebook, Google, and Adobe. These companies operate at large scale and still see benefits in relational databases.

Hopefully you found this article useful and if you want to learn more about the SQL and the JOIN, we recommend checking out Learning SQL: Master SQL Fundamentals.

Thanks for reading!