SQL Joins: Product - Id Product - Name Supplier - Name Unit - Price
SQL Joins: Product - Id Product - Name Supplier - Name Unit - Price
SQL Joins are used to relate information in different tables. A Join condition is a part of the sql query that retrieves rows from two or more tables. A SQL Join condition is used in the SQL WHERE Clause of select, update, delete statements. The Syntax for joining two tables is:
SELECT FROM
col1, table_name1,
col2,
col3... table_name2
supplier_name unit_price Nikon Onida Vediocon Apple Nokia 300 100 150 75 50
total_units 30 5 25 10
SQL Joins can be classified into Equi join and Non Equi join. 1) SQL Equi joins It is a simple sql join condition which uses the equal sign as the comparison operator. Two types of equi joins are SQL Outer join and SQL Inner join. For example: You can get the information about a customer who purchased a product and the quantity of product. 2) SQL Non equi joins It is a sql join condition which makes use of some comparison operator other than the equal sign like >, <, >=, <=
SELECT FROM
order_id,
product_name,
unit_price, product,
supplier_name,
total_units order_items
SELECT FROM
o.order_id,
p.product_name, product
p.unit_price, p,
p.supplier_name, order_items
o.total_units o
SELECT FROM
p.product_id, order_items
p.product_name, o,
o.order_id, product
o.total_units p
product_id product_name order_id total_units ------------- ------------100 101 Camera Television 5103 10 ------------- -------------
5 25 30
NOTE:If the (+) operator is used in the left side of the join condition it is equivalent to left outer join. If used on the right side of the join condition it is equivalent to right outer join.
SELECT FROM
a.sales_person_id, sales_person
a.name,
a.manager_id, a,
b.sales_person_id, sales_person
b.name b
SELECT FROM
first_name,
last_name,
subject student_details
first_name last_name subject ------------- ------------- ------------Anajali Shekar Rahul Stephen Bhagwat Gowda Sharma Fleming Maths Maths Science Science