DevShivmohan / Learning-everything

Learning for developer only
0 stars 1 forks source link

MySQL : Shivmohan : explain join operations #1

Open DevShivmohan opened 2 years ago

DevShivmohan commented 2 years ago

All join operations perform between these two tables personal and professional

image

Syntax- SELECT column_list
FROM table1, table2.... WHERE table1.column_name = table2.column_name;

Example- SELECT personal.id,personal.name,professional.dept,professional.work FROM personal,professional WHERE personal.id=professional.id;

image

OR

Syntax- SELECT column_list FROM table1
JOIN table2 [ON (join_condition)]

Example- SELECT personal.name,personal.address,professional.dept,professional.work FROM personal JOIN professional ON personal.id=professional.id;

image

Syntax- SELECT *
FROM table_name1, table_name2
WHERE table_name1.column [> | < | >= | <= ] table_name2.column;

Example- SELECT * FROM personal,professional WHERE personal.id < professional.id;

In this query personal.id less then professional.id that record are joined image

DevShivmohan commented 2 years ago

Join multiple table at a time

SELECT customerName, customercity, customermail, ordertotal,salestotal
FROM onlinecustomers AS c
   INNER JOIN
   orders AS o
   ON c.customerid = o.customerid
   LEFT JOIN
   sales AS s
   ON o.orderId = s.orderId
   WHERE s.salesId IS NULL
DevShivmohan commented 2 years ago

Join operations using alices

select * from user_master as um join user_role_map as urm on um.user_id=urm.user_id+.....+where urm.role_id=5;

DevShivmohan commented 2 years ago

Note

Equi join = Natural join = Inner join these are same equality;

Natural join syntax select * from <table_name1> natural join <table_name2>;

Inner join syntax select * from <table_name1> inner join <table_name2> on <table_name1>.<column_name>=<table_name2>.<column_name>;

Cross join syntax select * from <table_name1> cross join <table_name2>; If we have two tables every table has 5 records then result of cross join *55** [25] records;

Outer join