

These pieces of information are combined together using the JOIN and ON keywords. To join one table to another, PostgreSQL needs to know several pieces of information: Let's first focus on the second part of the statement, the part that joins the tables: FROM table_name1 Is essentially the SELECT column_list form that you've already seen in previous SELECT queries, with the slight difference that column names are prepended by table names in the column list. The first part of this: SELECT table_lumn_name. ) in the above command format indicates that we can provide any number of columns with the table_lumn_name format. The general syntax of a JOIN statement is as follows: SELECT table_lumn_name. We'll take a look at each type of JOIN in turn, but first lets go over the general syntax that JOIN statements share.


There are several types of JOINs: INNER, LEFT OUTER, RIGHT OUTER, FULL OUTER and CROSS they all do slightly different things, but the basic theory behind them all is the same. JOINs are clauses in SQL statements that link two tables together, usually based on the keys that define the relationship between those two tables.

SQL handles queries across more than one table through the use of JOINs. Now that this data is split across three tables, users, books, and checkouts, we first have to join those tables together before we can select the data that we need. This would return us the first two rows from that table, containing information such as the book title and author, and checkout and return dates. For example, looking at our unnormalized table below, if we wanted information on the books that 'John Smith' has checked out, we could use a simple SELECT query such as SELECT * WHERE full_name = 'John Smith'. When our data was all in a single table, we could easily retrieve a particular row from that table in order to get all the pertinent data we needed for a particular query.
