6c.sql Handson Joins
6c.sql Handson Joins
> insert into courses values ('BBB', 'Tableau'), ('CCC', 'Python'), ('DDD', 'Data
Analytics'), ('EEE', 'SQL');
> insert into students values ('AAA', 22), ('BBB', 24), ('CCC', 25), ('DDD', 30);
Inner Join:
> select name, course, age from students inner join courses on name = name; ---
column reference "name" is ambiguous
> select students.name, age, course from students inner join courses on
students.name = courses.name;
Left Join:
select students.name, age, course from students left join courses on students.name
= courses.name;
Right Join:
select students.name, age, courses.name, course from students right join courses on
students.name = courses.name;
Full Join:
select students.name, age, courses.name, course from students full join courses on
students.name = courses.name;
--- Full join is not supported in MySQL
Cross Join:
select students.name, age, courses.name, course from students cross join courses;
> insert into school (name, age) values ('Ram', 10), ('Ravi', 20);
Eg 2:
> CREATE TABLE products ( product_no integer, name text, price numeric CHECK (price
> 0));
> insert into emp (name, dept, salary) values ('Ravi Kiran', 'HR', 40000.00),
('Priya Darshini', 'IT', 25000.00),('Mohan Bhargav', 'Finance', 30000.00);