SQL Joins
SQL Joins SQL Joins: A joins is a relational operation that combines row in one table to the rows in another table related table according to common values existing in…
SQL Joins With Table: A joins is a relational operation that combines row in one table to the rows in another table related table according to common values existing in corresponding columns such as primary and foreign key columns.
The joins condition is specified with WHERE clause of SELECT statement. You may join two tables if each one contains a column with same domain of values. It must be noted that to join multiple tables, there should be one WHERE condition for each pair of tables being joined. Thus if N tables are to be combined, there should be N-1 WHERE condition.
Join is the combination of product, projection and selection operations. If selection operation is omitted, then the resultant table may contain duplicated rows.
There are the following types of joins
Equi-joins is the type of join in which joining condition is based on the equality (=) between values in common columns.
For example, to retrieve data from STUDENT and RESULT table the SELECT statement is written as:
SELECT Student.Roll_no,Student.Name,Student.City,Result.Roll_no,Result.Marks
FROM Student,Result
WHERE Student.Roll_no = Result.Roll_no
The result of the above query is
Student.Roll_no | Name | City | Result.Roll_no | Marks |
1 | Ali | Lahore | 1 | 895 |
2 | Hamza | Multan | 2 | 664 |
SQL Joins SQL Joins: A joins is a relational operation that combines row in one table to the rows in another table related table according to common values existing in…