Reputation: 644
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();
Upvotes: 3
Views: 3781
Reputation: 644
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();
Upvotes: 4
Reputation: 1370
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
Upvotes: 0