LEFT JOIN සහ RIGHT JOIN

LEFT JOIN
අපි කලින් INNER JOIN කළා නේ. LEFT JOIN කියන්නෙත් ඒ වගේම JOIN එකක්. නමුත් LEFT JOIN එකේ විශේෂත්වය තමයි වම් පැත්තේ තියන table එකේ සියලුම records ඔක්කොමත් මේ JOIN එකෙන් select වෙනවා. 





සාමාන්‍යන් අපේ left table එක වෙන්නේ අපි FROM keyword එක යොදාගන්න table එක. අපි example එකක් කරලා බලමු. මේ example එකට අපේ table එකේ පොඩි වෙනසක් කරන්න උනා. managersලා නැති departments දෙකකුත් මම add කළා



SELECT department.DepID, employees.Name, department.NoOfEmployees
FROM department
LEFT JOIN employees
ON department.ManagerEmpID=employees.ID;


මෙතැනදී බලාගන්න පුළුවන් department table එකේ අපි select කරපු column වල ඔක්කොම records select වෙලා තියනවා. හැබැයි employees table එකේ select කරපු column වලින් employee සහ department table දෙකේම තියන records ටික තමයි select වෙලා තියන්නේ.

RIGHT JOIN 
මෙතන වෙන්නේ කලින් එකේ left table එකට උන දේම right table එකට වෙන එක. ඉතින් මම හිතන්නේ නෑ ලොකු පැහැදිලි කිරීමක් ඕනේ කියලා.



SELECT department.DepID, employees.Name, department.NoOfEmployees
FROM department
RIGHT JOIN employees
ON department.ManagerEmpID=employees.ID;