Have you found the concepts of JOINS in SQL tricky? πŸ˜΅β€πŸ’«

A Beginner-Friendly JOINS guide that would help you in your SQL & Data Science Journey.

Thread 🧡
β˜‘οΈ JOINS (Some Theory)
Using JOIN, we can query data from two or more tables based on the related column present in both tables.

While performing a join, we need to specify the shared column & the condition on which we want to join tables.
β˜‘οΈ Types of JOINS:-
1. Inner Join
2. Left Join
3. Right Join
4. Full Join
β˜‘οΈ Inner Join
This join query would return rows when there is AT LEAST ONE ROW in both the tables that match the specified join condition.

πŸ‘‰ Query: select tablename1.col1, tablename2.col2 from tablename1 INNER JOIN tablename2 ON tablename1.col1 = tablename2.col2 Inner join of the two tables.
In the above query,

1. tablename1.col1 means the column1 in tablename1

2. We have to mention after the SELECT keyword which columns we want to apply Join Function on.

3. tablename1.col1 = tablename2.col2 is the condition using which we want our INNER JOIN to consider.
Consider an example of 2 tables having 2 columns each, namely ID and Name.

See the tables in the figure below:- Table 1Table 2
We perform a query to find the inner join.

Query -> select * from table1 inner join table2 on table1.name = table2.ID

i.e. selecting all the columns from table1 & table 2 to perform an inner join on the condn that name col of table1 = ID col of table2 Query for Inner Join
Look at the following explanation for the above query performed for more clarity:-

See Image Explanation for an inner join query
β˜‘οΈ Left Join
Using LEFT JOIN, the query returns all the rows from the left table and only those rows from the right table where the join condition is matched.

Query: select tablename1.col1, tablename2.col2 from tablename1 LEFT JOIN tablename2 ON tablename1.col1 = tablename2.col2 Left Join
Example: Consider the same 2 tables we considered for the inner join.

Query: select * from table1 LEFT JOIN table2 on table1.name = table2.ID

Observe the results in the image below. Result of a LEFT JOIN Query
Notice that the left table, i.e. the table 1, is entirely printed, and only those values of table 2 (the right side table) are printed where the join condition is met.
β˜‘οΈ Right Join
It functions similar to the left join, but the only difference is that it returns all the rows from the RIGHT table and only those rows from the left table where the join condition is matched. Right Join
Query: select * from tablename1 RIGHT JOIN tablename2 ON tablename1.col1 = tablename2.col2

Try to implement this one yourself. :)
β˜‘οΈ Full Join
It returns all rows when there is a match in either the left or the right table. Full Join

β€’ β€’ β€’

Missing some Tweet in this thread? You can try to force a refresh
γ€€

Keep Current with Sukriti Macker

Sukriti Macker Profile picture

Stay in touch and get notified when new unrolls are available from this author!

Read all threads

This Thread may be Removed Anytime!

PDF

Twitter may remove this content at anytime! Save it as PDF for later use!

Try unrolling a thread yourself!

how to unroll video
  1. Follow @ThreadReaderApp to mention us!

  2. From a Twitter thread mention us with a keyword "unroll"
@threadreaderapp unroll

Practice here first or read more on our help page!

More from @Sukriti_Macker

7 Jun
Want to pursue Data Science? SQL is the most imperative skill required in it!

A Beginner's Guide to MySQL Queries part 4! πŸ“–
RETRIEVAL & LOADING the data!

Thread 🧡
βœ… RETRIEVE THE DATA

The SELECT command allows the retrieval of information as per our requirements.

You can select/retrieve:-
1. All the data from the table using *
2. A single column
3. Multiple columns
1️⃣ Select all columns of the table

SELECT * from table_name;

πŸ‘‰ E.g., Selecting/Retrieving all the values from the classroom1 table.

2️⃣ Select one column from the table

SELECT column_name from table_name;

πŸ‘‰ E.g., Selecting the student_name column from the table classroom1. Retrieving ALL the columns ...Retrieving ONE column from ...
Read 5 tweets
6 Jun
SQL is the most wanted skill in Data Science!! 😱

A Beginner's Guide to MySQL basic queries - Part 3!! 😎

Making mistakes while creating tables is common. Let's learn how to update and fix them! 😬

Thread 🧡
βœ… UPDATE THE TABLE

1. Add a column to the existing table:-

ALTER table table_name ADD (column_name datatype);

(Note: Adding a constraint to a column is optional)

πŸ‘‰ E.g., Adding the ADDRESS column to the classroom1 table. Addition of a new column to the table classroom1
2. Add MULTIPLE columns at once:-

ALTER table table_name ADD (colname1 datatype1, colname2 datatype2);

πŸ‘‰ E.g., Adding Email_id and ContactNo columns to the classroom1 table Adding multiple columns at once in classroom1 table.
Read 7 tweets
5 Jun
Basic Queries MySQL part 2 (Let's fill the table up!) 😎

Beginner Friendly!

Thread 🧡
βœ… What are the keys in a relational database?
Keys help you uniquely identify a row in the table. It is also used to create relationship amongst various tables in a database.

The major types of keys:-
Primary Key
Candidate Key
Super Key
Foreign Key
Super Key: A set of one or more attributes or columns that identify a row/record in the table. It may consist of some columns that are not needed for the unique identification of a row.
Read 12 tweets
4 Jun
SQL is a crucial skill for a Data Scientist! I would be releasing everything I know, little by little, and then a compiled version of all the threads you could revisit.

A Beginner's Guide to MySQL basic queries 😎 -Part 1 (Creation of Everything!)

Thread 🧡
What is a database?
An organised collection of data that can be interrelated & makes operations like retrieval, insertion & deletion of data efficient.
User can perform different queries to perform an action based on their requirements.

Types:-
Hierarchical
Network
OO Database
A relational database is a type of database that stores everything in relations or tables.
Tables have columns and rows.

SQL -> Structured Query Language used to interact with a relational database.
Read 10 tweets
2 Jun
I had attended a webinar recently and learnt something incredibly unique! I discovered that you could be a Data Scientist, but having a #specialisation is IMPORTANT!

What is a "specialisation"? How many kinds of specialisations are there in #DataScience Domain?

Thread🧡 Image
*Specialisation*
One can acquire all the skills of a Data Scientist, but having specialisation in a particular skill can set you apart from the rest. It can be anything! You can analyse data as no one else; data visualisation or database management (#DBMS) could be your niche.🀩
β˜‘οΈData Visualisation
If you have a knack for producing beautiful graphical representations from the data, this could be your domain of specialisation, and you could become a Data #Visualisation Engineer. Image
Read 10 tweets
31 May
You want to step into the field of DATA. But do you know which area is best suited for you?

Compare your skills with the domain you are interested!!
Thread🧡
β˜‘οΈData Analyst
If you don't know what role Data Analyst plays, check out this (cutt.ly/VndBSnI)

Skills:-
Python and R
SQL
Excel
Data Visualisation Tools πŸ“ŠπŸ“ˆπŸ“‰
Report Building Tools (like Power BI & Tableau)
Communication, Presentation & Critical Thinking skills
β˜‘οΈMachine Learning Engineer
If you don't know what role Machine Learning Engineer plays, check out this (cutt.ly/VndBSnI)
Read 6 tweets

Did Thread Reader help you today?

Support us! We are indie developers!


This site is made by just two indie developers on a laptop doing marketing, support and development! Read more about the story.

Become a Premium Member ($3/month or $30/year) and get exclusive features!

Become Premium

Too expensive? Make a small donation by buying us coffee ($5) or help with server cost ($10)

Donate via Paypal Become our Patreon

Thank you for your support!

Follow Us on Twitter!

:(