Revision Mysql Join
Revision Mysql Join
CLASS : XII
COMPUTER SCIENCE
JOIN
When we perform Cartesian product between two tables, all the rows in the
first table are joined to all the rows in the second table.
EQUI JOIN:
The join in which columns are compared for equality is called Equi-
Join.
In equi-join * is used in select command therefore the common column
will appear twice in the output.
EXAMPLE:
Alias :
We can also give table alias (short name) for table and further use them
in query in place of table name.
This is helpful when table name is of big length & we can shorten the
query.
EXAMPLE:
SELECT * FROM employee e , dept d
WHERE e.deptno = d.deptno;
The join in which only one of the identical columns exists is called
Natural Join.
In natural join we specify the names of columns to fetch in such a way
so that identical columns appears only once.
EXAMPLE:
SELECT employee.* , dname, loc FROM employee , dept
WHERE employee.deptno = dept.deptno;
EXAMPLE:
EXAMPLE:
EXAMPLE:
QUESTIONS ON JOIN
1. Consider the following table GAMES. Write SQL commands for the
following statements.
(i) To display game type and the number of each type of game.
SELECT type , count(type) FROM Game GROUP BY type;
(ii) To display the maximum prize money in each types of game.
SELECT type , max(prizemoney) FROM Game
GROUP BY type;
(iii) To display sum of PrizeMoney for each Type of GAMES.
SELECT type , sum(prizemoney) FROM Game
GROUP BY type;
2. Consider the following table CABHUB. Write SQL commands for the
following statements: