join() public method

The table(s) to which this query should join. Returns this object for chaining purposes.
public join ( string $TableName, string $On, string $Join = '' ) : Gdn_SQLDriver
$TableName string The name of a single table to join to.
$On string The conditions on which the join should occur. ie. "user.role_id = role.id"
$Join string The type of join to be made. Accepted values are: 'inner', 'outer', 'left', 'right', 'left outer', and 'right outer'.
return Gdn_SQLDriver $this
 /**
  *
  *
  * @param Gdn_SQLDriver $Sql
  * @param $Tag
  * @param $Limit
  * @param int $Offset
  * @param string $Op
  * @throws Exception
  */
 protected function _setTagSql($Sql, $Tag, &$Limit, &$Offset = 0, $Op = 'or')
 {
     $SortField = 'd.DateLastComment';
     $SortDirection = 'desc';
     $TagSql = clone Gdn::sql();
     if ($DateFrom = Gdn::request()->get('DateFrom')) {
         // Find the discussion ID of the first discussion created on or after the date from.
         $DiscussionIDFrom = $TagSql->getWhere('Discussion', array('DateInserted >= ' => $DateFrom), 'DiscussionID', 'asc', 1)->value('DiscussionID');
         $SortField = 'd.DiscussionID';
     }
     $Tags = array_map('trim', explode(',', $Tag));
     $TagIDs = $TagSql->select('TagID')->from('Tag')->whereIn('Name', $Tags)->get()->resultArray();
     $TagIDs = array_column($TagIDs, 'TagID');
     if ($Op == 'and' && count($Tags) > 1) {
         $DiscussionIDs = $TagSql->select('DiscussionID')->select('TagID', 'count', 'CountTags')->from('TagDiscussion')->whereIn('TagID', $TagIDs)->groupBy('DiscussionID')->having('CountTags >=', count($Tags))->limit($Limit, $Offset)->orderBy('DiscussionID', 'desc')->get()->resultArray();
         $Limit = '';
         $Offset = 0;
         $DiscussionIDs = array_column($DiscussionIDs, 'DiscussionID');
         $Sql->whereIn('d.DiscussionID', $DiscussionIDs);
         $SortField = 'd.DiscussionID';
     } else {
         $Sql->join('TagDiscussion td', 'd.DiscussionID = td.DiscussionID')->limit($Limit, $Offset)->whereIn('td.TagID', $TagIDs);
         if ($Op == 'and') {
             $SortField = 'd.DiscussionID';
         }
     }
     // Set up the sort field and direction.
     saveToConfig(array('Vanilla.Discussions.SortField' => $SortField, 'Vanilla.Discussions.SortDirection' => $SortDirection), '', false);
 }