Skip to content

Commit c1e122e

Browse files
committed
add DISTINCT for select() method
1 parent 412b708 commit c1e122e

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

src/QueryBuilder.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,7 @@ public function query(string $sql = '', array $params = [], $column = 0, int $fe
518518
* @param array|string $fields
519519
* @return $this
520520
*/
521-
public function select($table, $fields = '*'): QueryBuilder
521+
public function select($table, $fields = '*', $dist = false): QueryBuilder
522522
{
523523
if (empty($table) || empty($fields)) {
524524
$this->setError('Empty $table or $fields in ' . __METHOD__);
@@ -527,8 +527,11 @@ public function select($table, $fields = '*'): QueryBuilder
527527

528528
$this->reset();
529529

530+
$this->sql = "SELECT ";
531+
$this->sql .= $dist ? "DISTINCT " : '';
532+
530533
if (is_array($fields) || is_string($fields)) {
531-
$this->sql = "SELECT {$this->prepareAliases($fields)}";
534+
$this->sql .= $this->prepareAliases($fields);
532535
} else {
533536
$this->setError('Incorrect type of $fields in ' . __METHOD__ . '. $fields must be a string or an array');
534537
return $this;

0 commit comments

Comments
 (0)