Mysql Join

Mysql Join is used to join the records from two table using join clause. The
Join Clause return you the set of records from both table on the basis of common
column. The Join return you only matchable records from both table on the basis
of where clause .The inner join does not return the unmatchable or null value
.
Understand with Example
The Tutorial illustrate an example from 'Join in Mysql'. To grasp this
example, we create a table roseindia with required field name and data type.
Query to Create Table named roseindia:-
mysql> create table roseindia(Empid int,firstname varchar(30));
Query OK, 0 rows affected (0.05 sec)
|
Query to insert data into Table named roseindia:-
Insert into insert the records or rows to the
table roseindia.
mysql> insert into roseindia values(01,'Girish');
Query OK, 1 row affected (0.02 sec)
mysql> insert into roseindia values(02,'Komal');
Query OK, 1 row affected (0.00 sec)
mysql> insert into roseindia values(03,'Amit');
Query OK, 1 row affected (0.02 sec)
mysql> insert into roseindia values(04,'Sandeep');
Query OK, 1 row affected (0.03 sec)
|
Query to view data of Table named roseindia:-
To view the records we use select query that
return records from 'roseindia'.
mysql> select * from roseindia;
|
Output:-
+-------+-----------+
| Empid | firstname |
+-------+-----------+
| 1 | Girish |
| 2 | Komal |
| 3 | Amit |
| 4 | Sandeep |
+-------+-----------+
4 rows in set (0.00 sec)
|
Query to Create Table newstrack:-
The createtable newstrack is used to
create a table newtrack.
mysql> create table newstrack(Empid int, lastname varchar(30));
Query OK, 0 rows affected (0.03 sec)
|
Query to insert data into Table named newstrack:-
We use insertinto add the records or rows into
the table newstrack.
mysql> insert into newstrack values(01,'Suman');
Query OK, 1 row affected (0.02 sec)
mysql> insert into newstrack values(02,'Ravi');
Query OK, 1 row affected (0.01 sec)
mysql> insert into newstrack values(03,'Santosh');
Query OK, 1 row affected (0.01 sec)
mysql> insert into newstrack values(04,'Vinod');
Query OK, 1 row affected (0.03 sec)
|
Query to view data of Table named newstrack:-
mysql> select * from newstrack;
|
Output:-
+-------+-----------+
| Empid | firstname |
+-------+-----------+
| 1 | Suman |
| 2 | Ravi |
| 3 | Santosh |
| 4 | Vinod |
+-------+-----------+
4 rows in set (0.00 sec)
|
Query to join the data of the above two tables named
roseindia and newstrack:-
The Query join returns you the matchable set of
records from tables roseindia and newstrack on the basis of common column.
mysql> select * from roseindia,newstrack
-> where roseindia.empid=newstrack.empid;
|
Output:-
+-------+-----------+-------+-----------+
| empid | firstname | empid | firstname |
+-------+-----------+-------+-----------+
| 1 | Girish | 1 | Suman |
| 2 | Komal | 2 | Ravi |
| 3 | Amit | 3 | Santosh |
| 4 | Sandeep | 4 | Vinod |
+-------+-----------+-------+-----------+
4 rows in set (0.02 sec)
|

|