-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInnerJoin.sql
45 lines (37 loc) · 1.06 KB
/
InnerJoin.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
CREATE TABLE employees (
employee_id INT PRIMARY KEY,
name VARCHAR(50) NOT NULL,
department_id INT
);
INSERT INTO employees (employee_id, name, department_id) VALUES
(1, 'Alice', 101),
(2, 'Bob', 102),
(3, 'Charlie', 103),
(4, 'David', 104),
(5, 'Eve', NULL);
----------------------------------------------------------------
CREATE TABLE departments (
department_id INT PRIMARY KEY,
department_name VARCHAR(50) NOT NULL
);
INSERT INTO departments (department_id, department_name) VALUES
(101, 'HR'),
(102, 'IT'),
(104, 'Finance'),
(105, 'Marketing');
----------------------------------------------------------------
SELECT employees.name, departments.department_name
FROM employees
INNER JOIN departments
ON employees.department_id = departments.department_id;
NEXT:
SELECT * FROM employees
INNER JOIN departments
ON employees.department_id = departments.department_id;
NEXT:
SELECT *
FROM employees as e
INNER JOIN departments as d
ON e.department_id = d.department_id;
NOTE: Must 2 ta table a common column thakte hobe, Tacara Join
Kaj korbe na !