SQL Join 157a (6) Flashcards

1
Q

SQL Join

A

● As the name shows, JOIN means to combine something. In case of SQL, JOIN means “to
combine two or more tables”.
● The SQL JOIN clause takes records from two or more tables in a database and combines it
together.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

Why is SQL join used?

A

● If you want to access more than one table through a select statement.
● If you want to combine two or more table then SQL JOIN statement is used .it
combines rows of that tables in one table and one can retrieve the information by a
SELECT statement.
● The joining of two or more tables is based on common field between them.
● SQL INNER JOIN also known as simple join is the most common type of join.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

What are the 4 different SQL joins?

For examples look at slides

A
  1. Inner join
  2. left join
  3. right join
  4. full join
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

Inner Join

For examples look at slides

A

● INNER JOIN selects records that have matching values in both tables as long as the condition is satisfied. It returns the combination of all rows from both the tables where the condition satisfies.

  • In other words combines the things that they have in common

Syntax: SELECT table1.column1,table1.colmun2, table2.column1,…FROM table1 INNER JOIN table2 ON table1.matching_column = table2.matching_column;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Left Join

For examples look at slides

A

● The SQL left join returns all the values from left table and the matching values from the right table. If there is no matching join value, it will return NULL.

  • In other words gets everything from the left + what the right side has in common with the left side.

Syntax:
SELECT table1.column1, table1.column2, table2.column1,…. FROM table1
LEFT JOIN table2 ON table1.matching_column = table2.matching_column;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Right Join

For examples look at slides

A

● The SQL RIGHT JOIN returns all the values from the values from the rows of right table and the matched values from the left table. If there is no matching in both tables, it will return NULL

  • In other words gets everything from the right plus what the left side has in common with the right side.

Syntax - SELECT table1.column1, table1.column2, table2.column1,…. FROM table1 RIGHT JOIN table2 ON table1.matching_column = table2.matching_column;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

Full Join

For examples look at slides

A

● In SQL, FULL JOIN is the result of a combination of both left and right outer join. Join tables have all the records from both tables. It puts NULL on the place of matches not found.

  • Combines everything from both tables

Syntax - SELECT table1.column1, table1.column2, table2.column1,…. FROM table1 FULL JOIN table2 ON table1.matching_column = table2.matching_column;

How well did you know this?
1
Not at all
2
3
4
5
Perfectly