I need to get the first row of table with where condition.
(new Query())
->select('*')
->from('stock_in')
->where("user_id = '$request_user_id'")
->andWhere("product_id = '$product_id'")
->andWhere("remaining_quantity > '0'")
->one();
Yes i got my answer.Use Limit there
(new Query())
->select('*')
->from('stock_in')
->where("user_id = '$request_user_id'")
->andWhere("product_id = '$product_id'")
->andWhere("remaining_quantity > '0'")
->limit('1')
->one();
To limit the result of a query you should use limit()
.
(new Query())
->select('*')
->from('stock_in')
->where("user_id = '$request_user_id'")
->andWhere("product_id = '$product_id'")
->andWhere("remaining_quantity > '0'")
->limit(2)
->all();
Documentation: http://www.yiiframework.com/doc-2.0/guide-db-query-builder.html#limit-offset