Skip to main content

SQL Joins

Are you aware of the fundamentals of a Set theory which entails a critical element for our database i.e. the concept of joins? Why do we need Joins in the database? Joins are the fundamental element if you want to combine various tables using a common or related column between them. Joins are mainly used in every analytical and business intelligence tool. 

Let's take a deep dive into the fundamentals of joins which is apparent by using a Venn diagram. There are mainly four types of joins- Inner, Left, Right, and Full outer join. Let's suppose we have two datasets A and B. When we focus on inner join it basically means the focus will be on the intersection or common columns present in both datasets. Similarly, the left join focuses on the dataset that is available in A and the common columns between both data sets. Right join is quite identical to left join but the main difference is it takes the data from B along with the common columns present between both data sets. Lastly, full outer join entails the complete data present in both A and B.

Source

This blog will mainly focus on SQL joins because that's the biggest dilemma for beginners where to use which joins when writing a query.  Let's remove the dust from this first we need to get familiar with the syntax query.


SELECT column_name(s)
FROM table1
INNER/OUTER/LEFT/RIGHT JOIN table2
ON table1.column_name = table2.column_name;


To configure it out you need to understand the Venn diagram that is mentioned above. Inner join is used when there is a commonality that exists between your data. Inner join identifies the data which is common and overlapping in nature. It returns the rows of data which has some exact matches. Whilst Outer join on other hand returns all rows including the ones which do not have any match or contains null values. Normally full outer join is not that popular when we consider MySQL database. An outer join will return all the data which is similar to taking a copy of the data in a common table. 

There's a big question which is needed to be addressed when we talk about inner and outer joins i.e. Can we use inner and outer join in the same query? Yes, it is possible to use both in the same query but keeping their order in mind because it can be tricky at times. According to my experience if you use LeftOuter Join before applying an Inner Join then you will get the desired results but it can be false too because it depends on the data and constraints you are working with. I would recommend you to have a look at Jeff Smith Blog. It will provide you greater insight when you are using multiple joins.

Comments

  1. Vstats- Student May 11, 2021 at 11:21 AM

    This was helpful. Thanks!

    Reply Delete
  2. Tarun Gupta May 12, 2021 at 4:31 PM

    Thank you!! Subscribe to my blog for more articles.

    Reply Delete
Add comment

Post a Comment

Popular posts from this blog

Ultimate Beginners Guide to DAX Studio

There are zillions of external tools available with Power BI but DAX Studio is one of the most commonly used tools to work with DAX queries. It is a perfect tool to optimize the DAX and the data model. In this blog let's shed some light on the basic functionalities that can take your report to the next level. ARE YOU READY?  To start you will need the latest version of the DAX Studio. You can download it from their website . Don't worry you don't have to pay for the license. Fortunately, DAX Studio is a free tool As a BI Developer, I am using DAX Studio regularly. Based on my experience I use it for several purposes but in this blog, I will highlight the most common ones. Extracting a dump of all the measures used in your PBIX. Why do we need to do this? It can be used for documentation purposes also sometimes we try to reuse the DAX and such a dump comes in handy in this scenario. How to achieve it? Open the DAX Studio it is located under the external tools once you open t

Do we really need Keepfilters in DAX?

Writing a DAX can be tricky at times and making it efficient for the system is always a challenge for a BI Developer. The most prominent example is the use of filters in DAX. There are zillion ways to filter something in DAX and attain the same result but when you look behind the scenes you will get to know what effect it makes on performance. Looking at the above image it all looks the same. In this blog, we will cover the most common scenarios to use filters including the use of filter with all, filter with values, and keepfilters. I am using the sample superstore data for demonstration. The idea is to get sales for "Tables". The DAX is as follows. The most common and basic approach will be this. Looking at the matrix it gives the sales amount of tables as the total sales for "Furniture". If we use this in a table or matrix results can be perplexing for the user. Considering the total it does make sense. But we want every sub-category to get their respective sales

Append v/s Merge in Power BI

Let's discuss another problem of the week. As a Power BI user, there are times when you want to combine queries. What are the ways to do so? In most cases, you can attain it by using either append or merge and both serve different purposes. Let's understand what do these terms mean in Power BI and how they are functionally different from each other.  It is quite common to get data from various sources and you need to combine those data depending on a particular column which is common in both tables so that you can add extra information or column to your big table. In such cases, we use merge queries. How to perform merge queries? For instance, I am considering Sample Superstore data and we will merge the returns table to the order table. You will find both merge and append in the home tab in extreme right in the power query editor. ProTip - You will find two options when you click on the drop-down in merge which are merge queries and merge queries as new. When you use merge que

代做工资流水公司广州打企业银行流水唐山个人工资流水 公司襄阳公司银行流水价格贵阳转账流水报价兰州工资银行流水价格衡阳工资流水单价格许昌转账银行流水代开珠海办理银行流水账单三亚薪资银行流水代办石家庄打印房贷流水镇江个人工资流水 公司海口打印工作收入证明鞍山制作车贷工资流水邯郸开银行流水单东莞企业对公流水价格南昌房贷流水办理哈尔滨查签证流水湖州打印企业对私流水莆田背调工资流水样本深圳查个人流水福州工资证明报价无锡打入职银行流水济南代做背调流水海口代开房贷银行流水孝感制作企业流水打印盐城打房贷流水肇庆查车贷银行流水西宁背调流水费用长沙贷款银行流水图片威海代开离职证明香港通过《维护国家安全条例》两大学生合买彩票中奖一人不认账让美丽中国“从细节出发”19岁小伙救下5人后溺亡 多方发声卫健委通报少年有偿捐血浆16次猝死汪小菲曝离婚始末何赛飞追着代拍打雅江山火三名扑火人员牺牲系谣言男子被猫抓伤后确诊“猫抓病”周杰伦一审败诉网易中国拥有亿元资产的家庭达13.3万户315晚会后胖东来又人满为患了高校汽车撞人致3死16伤 司机系学生张家界的山上“长”满了韩国人?张立群任西安交通大学校长手机成瘾是影响睡眠质量重要因素网友洛杉矶偶遇贾玲“重生之我在北大当嫡校长”单亲妈妈陷入热恋 14岁儿子报警倪萍分享减重40斤方法杨倩无缘巴黎奥运考生莫言也上北大硕士复试名单了许家印被限制高消费奥巴马现身唐宁街 黑色着装引猜测专访95后高颜值猪保姆男孩8年未见母亲被告知被遗忘七年后宇文玥被薅头发捞上岸郑州一火锅店爆改成麻辣烫店西双版纳热带植物园回应蜉蝣大爆发沉迷短剧的人就像掉进了杀猪盘当地回应沈阳致3死车祸车主疑毒驾开除党籍5年后 原水城县长再被查凯特王妃现身!外出购物视频曝光初中生遭15人围殴自卫刺伤3人判无罪事业单位女子向同事水杯投不明物质男子被流浪猫绊倒 投喂者赔24万外国人感慨凌晨的中国很安全路边卖淀粉肠阿姨主动出示声明书胖东来员工每周单休无小长假王树国卸任西安交大校长 师生送别小米汽车超级工厂正式揭幕黑马情侣提车了妈妈回应孩子在校撞护栏坠楼校方回应护栏损坏小学生课间坠楼房客欠租失踪 房东直发愁专家建议不必谈骨泥色变老人退休金被冒领16年 金额超20万西藏招商引资投资者子女可当地高考特朗普无法缴纳4.54亿美元罚金浙江一高校内汽车冲撞行人 多人受伤

代做工资流水公司 XML地图 TXT地图 虚拟主机 SEO 网站制作 网站优化