SQL Querying Multiple Tables: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 9: Line 9:


If more than one table appears in the <code>FROM</code> clause, then the condition used to '''link''' the tables must be included as well. This is the ANSI-approved method. of joining multiple tables, and it is the most portable across various database servers.
If more than one table appears in the <code>FROM</code> clause, then the condition used to '''link''' the tables must be included as well. This is the ANSI-approved method. of joining multiple tables, and it is the most portable across various database servers.
=Examples=
All examples provided in this article are based on three tables (<code>person</code>, <code>address</code> and <code>country</code>, with the following schema:
==<tt>person</tt>==
<font size=-2>
    Column  |        Type         
------------+------------------------
  id        | smallint             
  name      | character varying(30)
  birthday  | date                 
  address_id | smallint             
Indexes:
    "person_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "person_address_id_fkey" FOREIGN KEY (address_id) REFERENCES address(id)
</font>





Revision as of 20:01, 23 May 2024

External

Internal

Overview

More than one table can be used in a FROM query clause, and when that happens, it is said that the query performs a join.

Join Condition

If more than one table appears in the FROM clause, then the condition used to link the tables must be included as well. This is the ANSI-approved method. of joining multiple tables, and it is the most portable across various database servers.


Examples

All examples provided in this article are based on three tables (person, address and country, with the following schema:

person

   Column   |         Type          
------------+------------------------
 id         | smallint              
 name       | character varying(30) 
 birthday   | date                  
 address_id | smallint              
Indexes:
    "person_pkey" PRIMARY KEY, btree (id)
Foreign-key constraints:
    "person_address_id_fkey" FOREIGN KEY (address_id) REFERENCES address(id)


Foreign key

Join