SQL Joins

Jul 17, 2024 11:03 AM - 5 months ago 138286

SQLJoins intends combining information from 2 aliases much tables, based connected a related column. A array subordinate creates a impermanent array showing the information from the joined tables.

For example, we person 2 tables that follow, the array named tblcustomers stores the accusation astir the customer

idNameAddressRegDate
1John DoeNew Delhi2024-01-02
2Anuj kumarNoida UP2024-04-01
3Amit SinghBangalore Karnataka2024-05-01
4AlexChennai Tamilnadu2024-06-09

The tbloders array shop the accusation astir the individual orders pinch their corresponding amount:

idCustomer_IdProduct_NameAmount
11iPhone920000
22Sony TV45623
32Laptop85641
43Book456
54Toys1452

Rather than storing the customer sanction successful some tables, the tblorders array contains a reference to the customer id that appears successful tblcustomers table. We will usage subordinate to prime the corresponding information from some tables.

Syntax:

In the Above Syntax:

  • ColumnName1 successful TableName1 is usually that table’s Primary key.
  • ColumnName2 successful TableName2 is simply a Foreign Key successful that table.
  • ColumnName1 and ColumnName2 must person the aforesaid Data Type and for definite information types, the aforesaid size.

Example utilizing the supra 2 tables tblcustomers and tblorders

Output Will be:

idNameAddressProduct_NameAmount
1John DoeNew DelhiiPhone920000
2Anuj kumarNoida UPSony TV45623
2Anuj kumarNoida UPLaptop85641
3Amit SinghBangalore KarnatakaBook456
4AlexChennai TamilnaduToys1452
More