What are SQL Joins and Type of Joins?

What are SQL Joins and Type of Joins?

SQL Joins are keywords used to combine rows of two or more tables depending on the common field .


Type of Joins


1.Inner Join

2.Left Join
3.Right Join
4.Full Join
5.Self Join

Inner Join

Select all rows from both tables if there is a match between the columns in both tables
Photo
example 
consider two table 1 and table2

Select table1.columnname(you can write any no. of columns like this from table1),table2.Columnname(you can write any no. of columns like this from table2) from table1 inner join table2 on table1.columnname =table2.columnname (Here column name will be the name of the column on which you want to use join)

Left Join

It returns all rows from the left table(table1) and only matched rows form the right table(table2).
Photo
example 
consider two table 1 and table2

Select table1.columnname(you can write any no. of columns like this from table1),table2.Columnname(you can write any no. of columns like this from table2) from table1 left join table2 on table1.columnname =table2.columnname (Here column name will be the name of the column on which you want to use join)

Right Join

It return all the rows from the right table(table2) and only matched from the left table(table1) .
photo
example 
consider two table 1 and table2

Select table1.columnname(you can write any no. of columns like this from table1),table2.Columnname(you can write any no. of columns like this from table2) from table1 right join table2 on table1.columnname =table2.columnname (Here column name will be the name of the column on which you want to use join)

Full Join

It return all rows from left table and right table.
Photo
Select table1.columnname(you can write any no. of columns like this from table1),table2.Columnname(you can write any no. of columns like this from table2) from table1 full  join table2 on table1.columnname =table2.columnname (Here column name will be the name of the column on which you want to use join)

Self Join
if we join table to it self then it is called self join .



The SQL CROSS JOIN produces a result set which is the number of rows in the first table multiplied by the number of rows in the second table, if no WHERE clause is used along with CROSS JOIN. This kind of result is called as Cartesian Product.
If, WHERE clause is used with CROSS JOIN, it functions like an INNER JOIN.
An alternative way of achieving the same result is to use column names separated by commas after SELECT and mentioning the table names involved, after a FROM clause.


Comments

Popular posts from this blog

Handling Dynamic Web Tables Using Selenium WebDriver

Verify Specific Position of an Element

Read it out for TESTNG before going for an iterview