SQL Three Way Join Statement


Performs a join between three tables.

Syntax

SELECT select_columns FROM table_name INNER JOIN join_table ON join_criteria INNER JOIN join_table ON join_criteria
join_table:   table to join with
join_criteria:   where clause that specifies how records must match between the tables

Example


PreparedStatement stmt = conn.prepareStatement(
    "select id, socialsecuritynumber, memberships.personId, memberships.membershipname, resorts.resortname
    from persons inner join Memberships on persons.id = Memberships.PersonId inner join resorts on memberships.resortid = resorts.resortId
    where persons.id<2  order by persons.id desc, memberships.membershipname desc, resorts.resortname asc");

ResultSet ret = stmt.executeQuery();