L
L
Lev K2016-06-07 11:56:27
Yii
Lev K, 2016-06-07 11:56:27

How to create an is not null query in yii2?

Hello! I create a request like this:

$dr = TableName::find()->joinWith('idTb')
                            ->where(['is not', 'Date_end', null])
                            ->all();

The essence is that, it is necessary to select records where the 'Date_end' field is not null.
[0] =>
[1] =>
The query selects both 0 and 1, but only 1 is needed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
Greg Popov, 2016-06-07
@Gregpopov

$query = new Query;             
$query->select('ID, City,State,StudentName')
      ->from('student')                               
      ->where(['IsActive' => 1])
      ->andWhere(['not', ['City' => null]])
      ->andWhere(['not', ['State' => null]])
      ->orderBy(['rand()' => SORT_DESC])
      ->limit(10);

PS 2nd result in Google search for "yii2 not null"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question