SQL joins are used to query data from two or more tables,
based on a relationship between certain columns in these tables.
The JOIN keyword is used in an SQL statement to query data from two or more
tables, based on a relationship between certain columns in these tables.
Tables in a database are often related to each other with keys.
A primary key is a column
(or a combination of columns) with a unique value for each row. Each primary key value must be unique within
the table. The purpose is to bind data together, across tables, without
repeating all of the data in every
Look at the "Persons" table:
Note that the "P_Id" column is the primary key in the "Persons" table. This means that no two rows can have the same
persons even if they have the same name.
Next, we have the "Orders" table:
Note that the "O_Id" column is the primary key in the "Orders" table
and that the "P_Id" column refers to the
persons in the "Persons" table without using their names.
Notice that the relationship between the two tables above is the "P_Id"
Different SQL JOINs
Before we continue with examples, we will list the types of JOIN you can use,
and the differences between them.
- JOIN: Return rows when there is at least one match in both
- LEFT JOIN: Return all rows from the left table, even if
there are no matches in the right table
- RIGHT JOIN: Return all rows from the right table, even
if there are no matches in the left table
- FULL JOIN: Return rows when there is a match in one of
Learn XML with <oXygen/> XML Editor - Free Trial!
oXygen helps you learn to define,
edit, validate and transform XML documents. Supported technologies include XML Schema,
DTD, Relax NG, XSLT, XPath, XQuery, CSS.
Understand in no time how XSLT and XQuery work by using the intuitive oXygen debugger!
Do you have any XML related questions? Get free answers from the oXygen
and from the video
Download a FREE 30-day trial today!