Posts

Showing posts with the label Cross Join

CROSS JOIN Vs INNER JOIN In SQL

Image
Answer : Here is the best example of Cross Join and Inner Join. Consider the following tables TABLE : Teacher x------------------------x | TchrId | TeacherName | x----------|-------------x | T1 | Mary | | T2 | Jim | x------------------------x TABLE : Student x--------------------------------------x | StudId | TchrId | StudentName | x----------|-------------|-------------x | S1 | T1 | Vineeth | | S2 | T1 | Unni | x--------------------------------------x 1. INNER JOIN Inner join selects the rows that satisfies both the table . Consider we need to find the teachers who are class teachers and their corresponding students. In that condition, we need to apply JOIN or INNER JOIN and will Query SELECT T.TchrId,T.TeacherName,S.StudentName FROM #Teacher T INNER JOIN #Student S ON T.TchrId = S.TchrId SQL FIDDLE Result x--------------------------------------x | TchrId | TeacherName | StudentName | x----...