SQL JOIN is used to combine two or more tables based on primary key and foreign keys.
We use Join in conjunction with the table we normalize during database design. Consider a Department table we have in our previous example. We create a Department table that serves as our master file to be called from other table.
SQL JOIN can be very time consuming on large table, e.g. one with millions of records, since it has to match each row of one table, and check it with each row of other tables mentioned in the JOIN keyword.
Consider the following table for this exercise.
Please don't be confused with the previous table that we have used before. In the above example we have DeptID in the Users table and we also have DeptID in the Departments table. DeptID in the Departments table is the Primary key and DeptID in the Users table is the Foreign key. We can use those keys to create a join. They are responsible for combine two or more tables in our database.