![]() SQL database system |
JOINThe JOIN keyword, which is used as part of a SELECT command, allows a relational join to be performed on two or three tables. The JOIN .. ON syntax must be used; alternatives aren't supported. Usage:
SELECT ..
ExamplesSELECT c.name, t.description FROM customers (AS c) JOIN transactions (AS t) ON c.cust_id = t.cust_id select p.*, ps.currentstatus from patients = p left join patientstatus = ps on p.patientid = ps.patientid where ps.class = "B" order by p.patientid SELECT * FROM people JOIN pi_ref JOIN inst (as i) ON people.id = pi_ref.people_id AND pi_ref.inst_id = i.id ORDER BY people.lastname Usage notesWhen using JOIN, fieldnames must be specified using table.fieldname notation everywhere in the SQL command. Table name aliases may be defined using AS or = (as in the above examples); this helps to maintain brevity. ON binding specifies the key field(s) that will be matched up when performing the join. The only supported comparison operation is equality (=), and matching is case-insensitive. Multiple bindings may be connected using AND.
* Multiple rows having same key may be present on the left side or the right side. Multiple rows will be preserved in the join result if the appropriate jointype is used. Multiple rows having same key are never permitted on both left and right sides. The jointypes ending in DL are non-standard; DL stands for "duplicates in left side". Three-table joins are supported (see the 3rd example above). The 2nd and 3rd tables are joined first, then that result is joined with the first table. Each of these join operations has a left side and a right side, and its own jointype. Naming of the resultant fields is described in the SELECT manual page.
shsql performs joins by executing a separate program called shsql_join.
shsql_join must be in the current command PATH, or
in the dbbin directory as defined in your
project config file.
|
![]() Copyright Steve Grubb |