SQL Joins Example

SQL joins are combine rows from two or more sql tables.

Most Common join is : SQL INNER JOIN(Simple join). it returns all the rows from multiple tables where the join conditions met.

Let’s view at a selection from the “smitcky_order” table:

ID
Cust_id
Date
1000
1
2013-01-01
2000
5
2013-01-02
3000
10
2013-01-03

then, view at a selection from the smitcky_customer table:

Cust_id
Cust_name
Contact_name
1
Ronald
Maria Ronald
2
James
James bond
10
Charlie
Charlie monex

in “cust_id” column in the smitcky_customer table referes to the customer in the smitcky_customer table. in above both the table relationship colum is “cust_id”.

Example of sql statement query is:

SELECT smitcky_order.ID, smitcky_Customer.Cust_name, smitcky_order.Date
FROM smitcky_order
INNER JOIN smitcky_customer
ON smitcky_order.Cust_id=smitcky_Customer.Cust_id;

it will give result something like:

ID
Cust_name
Date
1000
Ronald
2013-01-01
3000
Charlie
2013-01-03