CLASS 12 Important Topic Joins in MySQL

CLASS 12 Important Topic Joins in MySQL 

Lets Take an example to perform Join operation on MySql Table. This is very important Topic Class 12 Board Exam point of view

Practice this example to Understand Joins in MySQL


 CREATE TABLE department(

DepartmentID INT PRIMARY KEY NOT NULL,
DepartmentName VARCHAR(20)
);

CREATE TABLE employee (
LastName VARCHAR(20),
DepartmentID INT REFERENCES department(DepartmentID)
);

INSERT INTO department
VALUES (31, 'Sales'),
(33, 'Engineering'),
(34, 'Clerical'),
(35, 'Marketing');

INSERT INTO employee
VALUES ('Rafferty', 31),
('Jones', 33),
('Heisenberg', 33),
('Robinson', 34),
('Smith', 34),
('Williams', NULL);
SELECT *
FROM employee INNER JOIN department ON 1=1;
SELECT *
FROM employee CROSS JOIN department;
SELECT *
FROM employee, department;
SELECT employee.LastName, employee.DepartmentID, department.DepartmentName
FROM employee
INNER JOIN department ON
employee.DepartmentID = department.DepartmentID;
SELECT employee.LastName, employee.DepartmentID, department.DepartmentName
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID;
SELECT *
FROM employee JOIN department
ON employee.DepartmentID = department.DepartmentID;
SELECT *
FROM employee, department
WHERE employee.DepartmentID = department.DepartmentID;
SELECT *
FROM employee INNER JOIN department USING (DepartmentID);








Post a Comment

0 Comments