public function join_correlated_subquery( Table $table, $this_column, $comparator, $other_column, Closure $callback, $type = 'INNER' ) {

		$this->assert_comparator( $comparator );

		$other_alias = 't' . ( ++ $this->alias_count );

		$other_query              = new FluentQuery( $table, $this->wpdb );
		$other_query->from        = new From( $table->get_table_name( $this->wpdb ), $other_alias );
		$other_query->alias       = $other_alias;
		$other_query->alias_count = $this->alias_count + 1;

		$other_query->joined_tables                 = $this->joined_tables;
		$other_query->joined_tables[ $this->alias ] = $this->table;

		$other_query->select->also( $other_query->prepare_column( $other_column ) );
		$other_query->take( 1 );
		$callback( $other_query );

		$from = new From( $table->get_table_name( $this->wpdb ), $other_alias );

		$where = new Where_Raw(
			"{$this->prepare_column( $this_column )} $comparator ({$other_query->build_sql()})"
		);

		$this->joins[] = new Join( $from, $where, $type );

		$this->joined_tables[ $other_alias ] = $table;

		return $this;
	}
public function join_correlated_subquery( Table $table, $this_column, $comparator, $other_column, Closure $callback, $type = 'INNER' ) {

		$this->assert_comparator( $comparator );

		$other_alias = 't' . ( ++ $this->alias_count );

		$other_query              = new FluentQuery( $table, $this->wpdb );
		$other_query->from        = new From( $table->get_table_name( $this->wpdb ), $other_alias );
		$other_query->alias       = $other_alias;
		$other_query->alias_count = $this->alias_count + 1;

		$other_query->joined_tables                 = $this->joined_tables;
		$other_query->joined_tables[ $this->alias ] = $this->table;

		$other_query->select->also( $other_query->prepare_column( $other_column ) );
		$other_query->take( 1 );
		$callback( $other_query );

		$from = new From( $table->get_table_name( $this->wpdb ), $other_alias );

		$where = new Where_Raw(
			"{$this->prepare_column( $this_column )} $comparator ({$other_query->build_sql()})"
		);

		$this->joins[] = new Join( $from, $where, $type );

		$this->joined_tables[ $other_alias ] = $table;

		return $this;
	}
public function join_correlated_subquery ( Table $ table , $ this_column , $ comparator , $ other_column , Closure $ callback , $ type = 'INNER' ) { $ this -> assert_comparator ( $ comparator ) ; $ other_alias = 't' . ( ++ $ this -> alias_count ) ; $ other_query = new FluentQuery ( $ table , $ this -> wpdb ) ; $ other_query -> from = new From ( $ table -> get_table_name ( $ this -> wpdb ) , $ other_alias ) ; $ other_query -> alias = $ other_alias ; $ other_query -> alias_count = $ this -> alias_count + 1 ; $ other_query -> joined_tables = $ this -> joined_tables ; $ other_query -> joined_tables [ $ this -> alias ] = $ this -> table ; $ other_query -> select -> also ( $ other_query -> prepare_column ( $ other_column ) ) ; $ other_query -> take ( 1 ) ; $ callback ( $ other_query ) ; $ from = new From ( $ table -> get_table_name ( $ this -> wpdb ) , $ other_alias ) ; $ where = new Where_Raw ( "{$this->prepare_column( $this_column )} $comparator ({$other_query->build_sql()})" ) ; $ this -> joins [ ] = new Join ( $ from , $ where , $ type ) ; $ this -> joined_tables [ $ other_alias ] = $ table ; return $ this ; }
Perform a join, but instead of comparing to a simple value,
use a correlated sub query to find the match.

Will automatically build the SELECT and LIMIT statements.

@param Table   $table        Table to join to.
@param string  $this_column  Column on the current table to check equality for.
@param string  $comparator   How to compare the two values, should likely be '='.
@param string  $other_column The column on the joined table to check.
@param Closure $callback     Callback receiving a FluentQuery to build the sub query from.
@param string  $type

@return $this
@throws InvalidColumnException
Perform a join but instead of comparing to a simple value use a correlated sub query to find the match .