Translate

Saturday, 18 May 2019

Joins in SQL – Inner, Outer, Left and Right Join

Here you will get detailed information about joins in SQL.

Join is a very basic concept in SQL which can be confusing at times. The joins are used when we need to find out the solution to a query involving the attributes of more than one table which have at least one attribute in common. Hence the need of join is pretty much clear in itself. There are different types of join which are used for different purposes.

Joins in SQL

Let’s say we have two tables, a table named STUDENT and the other table named TEACHER.

The first table “STUDENT” stores the reference details of the student and the second table “TEACHER” stores the details of the teachers who are in the school and the class they are teaching.

STUDENT

ClassID Name House address
101 Raj xyz
201 Varun byc
301 Chittiz abc
401 Hema def

TEACHER

Teacher id Class name ClassID
1 First 101
2 Second 201
3 Third 301
4 Fourth 401

In the second table, the “ClassID” is a foreign key which is used as a reference of the first table in the second one.

Now, if we want to find out the name of the student whose teacher id is 1; we need to find the join of the above mentioned tables since it requires us to gather the information of both the tables. Hence, the joins are only used where both the tables have at least one attribute (here ClassID) in common and we need to find the solution to a query which involves the attributes from both the tables.

Types of Join

Basically there are four types of joins namely, inner join, left join, right join, full outer join. The explanation of each one of the mentioned joins is as given below.

Joins in SQL - Inner, Outer, Left and Right Join

1. Inner Join

Let us consider the following two tables, the first table’s name is Country (saves the id of different countries) and the other table’s name is State (saves the various states in those countries).

COUNTRY

CountryId CountryName
1 China
2 India
3 USA

STATE

StateId CountryId StateName
01 2 GOA
02 2 RAJASTHAN
03 5 KATHMANDU
04 6 ISLAMABAD

select * from COUNTRY

inner join STATE

on COUNTRY.CountryId=STATE.CountryId

The above mentioned command applies an inner join on the two table, since the common attribute is Country id, we have applied the join on the same.

The inner join returns all the matching values from both the tables. Here, in table State, since the only matching CountryId value in the country table is {CountryId = 2}, as a result of the inner join we will get the following result:

CountryId CountryName StateId StateName
2 India 01 GOA
2 India 02 RAJASTHAN

2. Right Join

The  right (or right outer join) on the other hand, displays the data which is common in both the tables, as well as the data which is present in the right table (exclusively).

This basically means that the entire right table’s data would be displayed on application of a right join.

When there is no match in the Left Table, it displays NULL.

Example:

COUNTRY

CountryId CountryName
1 China
2 India
3 USA

STATE

StateId CountryId StateName
01 2 GOA
02 2 RAJASTHAN
03 5 KATHMANDU
04 6 ISLAMABAD

select * from COUNTRY

right  join STATE

on COUNTRY.CountryId=STATE.CountryId

The above mentioned command applies a right join on the two tables, since the common attribute is CountryId; we have applied the join on CountryId itself.

The right table is the second table we refer to.

We would get the following table as a result of the application of the right join:

CountryId CountryName StateId StateName
2 India 01 GOA
2 India 02 RAJASTHAN
5 NULL 03 KATHMANDU
6 NULL 04 ISLAMABAD

In the result, it is clearly depicted that the values in the Left Table which have absolutely no matching values in the Right one are not being displayed. Only those values of the Left Table are displayed which have common attributes with the Right one. Whereas all the values in the Right Table are displayed. The rows in the Right Table with no match in the Left Table are displayed as NULL (Empty).

3. Left Join

The left join (or left outer join) on the other hand, displays the data which is common in both the tables, as well as the data which is present in the left table (exclusively).

This basically means that the entire Left Table’s data would be displayed on application of a Left Join.

When there is no match in the Left Table, it displays NULL.

COUNTRY

CountryId CountryName
1 China
2 India
3 USA

STATE

StateId CountryId StateName
01 2 GOA
02 2 RAJASTHAN
03 5 KATHMANDU
04 6 ISLAMABAD

select * from COUNTRY

left join STATE

on COUNTRY.CountryId =STATE.CountryId

The above mentioned command applies a Left Join on the two tables, since the common attribute is CountryId; we have applied the join on Countryid itself.

The Left Table is the first table we refer to.

We would get the following table as a result on application of left join:

CountryId CountryName Stateid Statename
1 China NULL NULL
2 India 01 GOA
2 India 02 RAJASTHAN
3 USA NULL NULL

In the result, it is clearly depicted that the values in the right column which have absolutely no matching values in the left one are not being displayed. Only those attributes of the right column are displayed which have common attributes with the left one. Whereas all the values in the Left Table are displayed. The rows in the Left Table with no match in the Right Table are displayed as NULL (Empty)

4. Full Outer Join

The Full Outer Join, as the name suggests, shows all the content of both the tables. The Full Outer Join returns all matching records from both the tables whether the other table matches or not.

COUNTRY

CountryId CountryName
1 China
2 India
3 USA

STATE

StateId CountryId StateName
01 2 GOA
02 2 RAJASTHAN
03 5 KATHMANDU
04 6 CANADA

select * from COUNTRY

full outer join STATE

on COUNTRY.CountryId=TEACHER.CountryId

The above mentioned command applies a Full Outer Join on the two tables, since the common attribute is CountryId; we have applied the join on Countryid itself.

We would get the following table as a result on application of Full Outer Join:

CountryId CountryName Stateid Statename
1 China NULL NULL
2 India 01 GOA
2 India 02 RAJASTHAN
3 USA NULL NULL
NULL NULL 03 KATHMANDU
NULL NULL 04 ISLAMABAD

This Join results in all the rows. We get NULL (Empty), when there is no match.

Joins are essentially important to work with tables in SQL and the above mentioned description genuinely elaborate the usage of each one of them.

Comment down below if you have any queries related to SQL joins.

The post Joins in SQL – Inner, Outer, Left and Right Join appeared first on The Crazy Programmer.



Friday, 17 May 2019

DC: 1 Hacking Challenge Walkthrough (Vulnhub)

Today we will be cracking a boot2root machine which has been recently added to vulnhub i.e. DC:1. According to author,

DC: 1 Hacking Challenge Walkthrough (Vulnhub) on Latest Hacking News.



Report Reveals TeamViewer Was Breached By Chinese Hackers In 2016

The German software company behind TeamViewer, one of the most popular software in the world that allows users to access and share their desktops remotely, was reportedly compromised in 2016, the German newspaper Der Spiegel revealed today. TeamViewer is popular remote-support software that allows you to securely share your desktop or take full control of other's PC over the Internet from

SitePoint Premium New Releases: Flask, Pug, ECMAScript, Linux + More

We're working hard to keep you on the cutting edge of your field with SitePoint Premium. We've got plenty of new books to check out in the library — let us introduce you to them.

Mastering Flask Web Development Second Edition

Build modern, secure, production-ready web MVC apps and APIs using Python’s Flask framework. Utilize various extensions like Flask-JWT and Flask-SQLAlchemy to develop powerful applications. Deploy a Flask app on real-world platforms like AWS and Heroku on VMs or Docker containers.

Read Mastering Flask Web Development Second Edition.

React Native Blueprints

Develop real-world Android and iOS apps with React Native, building fun projects from scratch while discovering more efficient techniques. Learn to build professional Android and iOS apps with your JS skills. Use Isomorphic principles to build mobile apps that offer a native user experience.

Read React Native Blueprints.

A Beginner’s Guide to Pug

In this guide, we’ll demonstrate how to get up and running with Pug, a template engine for Node and for the browser. We’ll start by installing it, go over its basic syntax and then look at several examples of using JavaScript in Pug. Finally, we’ll explore a couple of Pug’s more advanced features.

Read A Beginner’s Guide to Pug.

ECMAScript Cookbook

Become a better web programmer by writing efficient and modular code using ES6 and ES8. Learn to write asynchronous code and improve app readability. Explore advanced concepts such as closures, generators and Promises. Use design patterns to create structures to solve common issues.

Read ECMAScript Cookbook.

Linux Essentials, 2nd Edition

Perfect for beginners, Linux Essentials Exam students, and those seeking a career in IT, this book presents task-based lessons on the basics of Linux, including distributions, types of apps, freeware, licensing, operations, navigation, command functions, user types, users and groups, and much more.

Read Linux Essentials, 2nd Edition.

And More to Come…

We're releasing new content on SitePoint Premium almost every day, so we'll be back next week with the latest updates. And don't forget: if you haven't checked out our offering yet, take our library for a spin.

The post SitePoint Premium New Releases: Flask, Pug, ECMAScript, Linux + More appeared first on SitePoint.



How to Launch a Side Project from Zero

Since 2017, I have launched several projects including Spider, Pretzel, Stitches and Dribbble color palette.

At first, it wasn't clear which steps of the launch process were more important than others. But after my third launch, I had hatched a plan and started tweaking it. In this article, I will share the lessons I learned and walk you through the process of making a product. Hopefully you can take this as a starting point or inspiration, and make something tailored for yourself.

Start by checking out this checklist that I've developed over a number of side projects. Feel free to run with it and adapt it for your own projects.

https://twitter.com/hyper_yolo/status/1116683418425683968

1. Keep a Problem Notebook

book_of_grudges

Many of us keep an idea notebook, but I would advocate keeping a “book of grudges”: one with problems and wrongs you find intriguing to solve. Mine is a kanban board with different labels — design, social, security, etc. With these labels, I know what problem could be easily solved with a post-it note, and what could be solved by a clever app. I stare at this board often and maintain it diligently — it tells me what my current priority is, and what the next long term goal is.

2. Know Yourself First

If you’re like me, your book of grudges is extensive. To figure out what is worth spending time on, let’s start with why. Why do you want to create a product?

For me, there are two reasons:

  1. I like helping people and listening to their daily struggles. It gives me different perspectives on life.
  2. Nothing brings me as much joy as making things. The satisfaction of creating something of my own is far greater than any shiny new job or huge paycheque.

With the two causes combined, I noticed I’m drawn to smaller and refined issues. You can spot a trend among all the products I've made — they are utilitarian and focused.

So, ask yourself why to narrow the field of selections. If new technologies and the possibilities they bring fascinate you, maybe an open-ended, AR powered camera app would excite you. Whatever you choose, starting by understanding your cause will help you feel less overwhelmed.

3. Ideation and Design

Once you have a problem to tackle and you’re armed with enough knowledge regarding the problem, it’s time to ideate the solution. During ideation, the only goal is to generate as many solutions as possible without being judgmental. I write my ideas out in a Markdown file and keep the session around 30 minutes.

The post How to Launch a Side Project from Zero appeared first on SitePoint.



Latest Hacking News Podcast #285

Stack Overflow Data Breach, Word Press Live Chat Vulnerability, Update On Hactivism From IBM, Linux RDS Patch Warning, Europol Announces

Latest Hacking News Podcast #285 on Latest Hacking News.



Week in security with Tony Anscombe

ESET researchers detail how ASUS's cloud service has been abused to distribute the Plead malware; in other news, ESET's telemetry shows that the use of the EternalBlue exploit is reaching new highs

The post Week in security with Tony Anscombe appeared first on WeLiveSecurity