Relational tables are linked through key columns so product, customer and transaction data can stay in separate tables without repeating the same details in every row. JOIN clauses then reconstruct the report you need.
Linking of table is a very common requirement in SQL. Different types of data
can be stored in different tables and based on the requirement the tables can be
linked to each other and the records can be displayed in a very interactive way.
We can link more than one table to get the records in different combinations as per requirement. Keeping data of one area in one table and linking them each other with key field is better way of designing tables than creating single table with more number of fields. For example in a student database you can keep student contact details in one table and its performance report in another table. You can link these two tables by using one unique student identification number ( ID ).
Let us take one example of linking of tables by considering product and customer
relationship. We have a product table where all the records of products are
stored. Same way we will have customer table where records of customers are
stored. The daily sales keep the record of all the sales. This sales table will
keep record of which product who has purchased. So linking is to be done from
Sales table to product table and customer table.
From these three tables let us find out the information on sales by linking
these tables. We will look into sales table and link it to the customer
table by the customer id field and in same way we will link product table by
product ID field. Older SQL often linked tables with comma-separated table lists and WHERE conditions. Modern examples are clearer with explicit INNER JOIN and ON conditions. Here
is the command to link three tables.
We may be interested to know which are the products not sold or who are the customers who have not purchased.
We can prepare such reports by using Left Join , RIGHT Join or INNER JOIN.
Joining tables Using SQL LEFT Join, RIGHT Join and Inner Join
I write and maintain practical tutorials on Python, PHP, SQL, JavaScript, HTML, jQuery,
and web development at plus2net. The tutorials focus on clear explanations, working
examples, and code that readers can test and adapt while learning.