Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

‭PRACTICAL 7‬

‭ ame:‬
N
‭Class:‬
‭Div:‬
‭Roll‬
‭no:‬
‭DOP:‬
‭DOS:‬
‭Grade‬
‭Sign:‬
‭Aim‬‭:‬‭To perform join operation using SQL‬

‭ heory‬‭:‬
T
‭Types of joins-‬

‭1.‬‭CROSS JOIN‬
‭2.‬‭INNER JOIN‬
‭3.‬‭OUTER JOIN-‬
‭i-‬‭LEFT OUTER‬
‭ii-‬‭RIGHT OUTER‬
‭iii-‬‭FULL OUTER‬

‭1.‬‭CROSS JOIN‬
‭ efinition:‬‭A‬‭CROSS‬‭JOIN‬‭in‬‭SQL‬‭is‬‭a‬‭join‬‭operation‬‭that‬‭combines‬‭each‬‭row‬‭of‬‭the‬‭first‬
D
‭table‬‭with‬‭every‬‭row‬‭of‬‭the‬‭second‬‭table,‬‭resulting‬‭in‬‭what‬‭is‬‭called‬‭the‬‭Cartesian‬‭product‬
‭of‬ ‭the‬ ‭two‬ ‭tables.‬ ‭This‬ ‭means‬ ‭that‬ ‭for‬ ‭every‬ ‭row‬ ‭in‬ ‭the‬ ‭first‬ ‭table,‬ ‭there‬ ‭will‬ ‭be‬ ‭a‬
‭corresponding‬ ‭row‬ ‭for‬ ‭each‬ ‭row‬ ‭in‬ ‭the‬ ‭second‬ ‭table.‬ ‭It‬ ‭is‬ ‭essentially‬‭a‬‭way‬‭to‬‭create‬‭all‬
‭possible combinations of rows from the two tables.‬

‭Syntax:‬
‭ ELECT * FROM table1‬
S
‭CROSS JOIN table2;‬

‭Querry:‬
‭Output:‬
‭1-‬‭INNER JOIN:‬
‭ n‬‭INNER‬‭JOIN‬‭in‬‭SQL‬‭is‬‭a‬‭type‬‭of‬‭join‬‭used‬‭to‬‭combine‬‭rows‬‭from‬‭two‬‭or‬‭more‬‭tables‬
A
‭based‬ ‭on‬ ‭a‬ ‭related‬ ‭column‬ ‭or‬ ‭columns‬ ‭between‬ ‭them.‬ ‭It‬ ‭selects‬ ‭only‬ ‭the‬ ‭rows‬‭that‬‭have‬
‭matching‬ ‭values‬ ‭in‬ ‭the‬‭specified‬‭columns‬‭from‬‭both‬‭tables,‬‭effectively‬‭filtering‬‭out‬‭rows‬
‭where‬ ‭there‬ ‭is‬ ‭no‬ ‭match.‬ ‭This‬ ‭type‬ ‭of‬ ‭join‬ ‭is‬ ‭particularly‬ ‭useful‬ ‭for‬ ‭retrieving‬ ‭data‬ ‭that‬
‭exists‬ ‭in‬ ‭both‬ ‭tables‬ ‭and‬ ‭is‬ ‭often‬ ‭used‬ ‭to‬‭connect‬‭related‬‭data‬‭across‬‭multiple‬‭tables‬‭in‬‭a‬
‭relational‬‭database.‬‭The‬‭INNER‬‭JOIN‬‭operation‬‭results‬‭in‬‭a‬‭new‬‭table‬‭with‬‭columns‬‭from‬
‭both‬ ‭tables,‬ ‭containing‬ ‭only‬ ‭the‬ ‭rows‬ ‭that‬ ‭satisfy‬ ‭the‬ ‭join‬ ‭condition.‬ ‭It‬ ‭helps‬ ‭in‬‭creating‬
‭meaningful‬ ‭relationships‬ ‭between‬ ‭tables‬ ‭and‬ ‭retrieving‬ ‭relevant‬ ‭data‬ ‭for‬ ‭analysis‬ ‭or‬
‭reporting purposes.‬

‭ YNTAX:‬
S
‭SELECT columns‬
‭FROM table1‬
‭INNER JOIN table2 ON table1.column = table2.column;‬
‭ UTER‬ ‭JOIN‬‭:‬ ‭Outer‬ ‭joins‬ ‭in‬ ‭SQL‬ ‭are‬ ‭essential‬ ‭for‬ ‭fetching‬ ‭data‬ ‭from‬ ‭multiple‬ ‭tables,‬
O
‭even‬ ‭when‬‭there‬‭might‬‭not‬‭be‬‭matching‬‭records‬‭in‬‭one‬‭or‬‭both‬‭tables.‬‭These‬‭joins‬‭come‬‭in‬
‭three varieties: LEFT OUTER JOIN, RIGHT OUTER JOIN, and FULL OUTER JOIN.‬

‭ EFT‬ ‭OUTER‬ ‭JOIN‬ ‭returns‬ ‭all‬ ‭records‬ ‭from‬‭the‬‭left‬‭table‬‭and‬‭matching‬‭records‬‭from‬‭the‬


L
‭right table, or NULL if no match is found in the right table.‬

‭ IGHT‬ ‭OUTER‬ ‭JOIN‬ ‭returns‬ ‭all‬ ‭records‬ ‭from‬ ‭the‬ ‭right‬ ‭table‬ ‭and‬ ‭matching‬ ‭records‬‭from‬
R
‭the left table, or NULL if no match is found in‬
‭ ULL‬ ‭OUTER‬ ‭JOIN‬ ‭:‬ ‭returns‬ ‭a‬‭result‬‭set‬‭that‬‭includes‬‭all‬‭rows‬‭from‬‭both‬‭tables‬‭being‬‭joined,‬
F
‭regardless‬ ‭of‬ ‭whether‬ ‭there‬ ‭is‬ ‭a‬ ‭matching‬‭row‬‭in‬‭the‬‭other‬‭table.‬‭If‬‭there‬‭is‬‭no‬‭match‬‭for‬‭a‬‭row‬
‭from‬ ‭one‬ ‭table‬ ‭in‬ ‭the‬‭other‬‭table,‬‭the‬‭columns‬‭from‬‭the‬‭non-matching‬‭table‬‭will‬‭contain‬‭NULL‬
‭values‬ ‭in‬ ‭the‬ ‭result‬ ‭set.‬‭The‬‭FULL‬‭OUTER‬‭JOIN‬‭ensures‬‭that‬‭no‬‭data‬‭is‬‭lost‬‭from‬‭either‬‭table,‬
‭making‬ ‭it‬ ‭useful‬ ‭for‬ ‭scenarios‬ ‭where‬ ‭you‬ ‭need‬ ‭to‬ ‭include‬ ‭all‬ ‭records‬ ‭from‬ ‭both‬ ‭tables,‬‭even‬‭if‬
‭they don't have matching values in the join condition.‬

‭Conclusion:‬
I‭ n‬ ‭this‬ ‭experiment,‬ ‭we‬ ‭explored‬ ‭different‬ ‭types‬ ‭of‬ ‭SQL‬ ‭joins‬ ‭using‬ ‭the‬ ‭DVD‬ ‭Rental‬
‭Database.‬ ‭Through‬ ‭various‬ ‭join‬ ‭operations‬ ‭like‬ ‭INNER,‬‭LEFT‬‭OUTER,‬‭RIGHTOUTER,‬
‭FULL‬ ‭OUTER,‬ ‭and‬ ‭CROSS‬ ‭joins,‬ ‭we‬ ‭learned‬‭how‬‭to‬‭combine‬‭data‬‭from‬‭multiple‬‭tables‬
‭efficiently.‬ ‭This‬ ‭exercise‬ ‭provided‬ ‭valuable‬ ‭insights‬ ‭into‬ ‭relational‬ ‭database‬ ‭querying,‬
‭highlighting‬ ‭the‬ ‭importance‬ ‭of‬ ‭understanding‬ ‭join‬ ‭types‬ ‭for‬ ‭effective‬ ‭data‬ ‭retrieval‬ ‭and‬
‭analysis.‬

You might also like