SQL JOINS

Information

The SQL JOIN types may come in handy if you're working with SQL databases a lot and need to prepare the data prior to importing it. It could also be used to simply retrieve relational information more quick.

The following SQL JOIN types have been made available:

  • CROSS JOIN
  • INNER JOIN
  • LEFT JOIN
  • RIGHT JOIN
  • OUTER JOIN
  • LEFT EXCLUDING JOIN
  • RIGHT EXCLUDING JOIN
  • OUTER EXCLUDING JOIN


See the Wikipedia site for an explanation of the different SQL types:


Syntax (JsDocs text from script)

/**
 * Create a CROSS join 
 *
 * @param {A1:B26} range1 first data range
 * @param {number|string} pk1 primary key of the first data range 
 * @param {C1:D26} range2 second data range
 * @param {number|string} pk2 primary key of the second data range 
 * @param {boolean} opt_header use TRUE to include a header range
 * @return The corresonding SQL join table
 * @customfunction
 */
function SQLCROSSJOIN(range1, pk1, range2, pk2, opt_header) {
  return sqlJoin(range1, pk1, range2, pk2, opt_header, CROSS);
}  

Examples

=SQLCROSSJOIN(A2:B8,2,A11:B15,1,true)                // Outputs the cross join, in which the second column of range1 acts as the
                                                     // primary key. The first column of range2 must be used as the primary key.

Video

Screenshot