Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Selecting specific column value with condition

Tags:

yii2

I want to get a specific column from User table in yii2 using active record below is my code

$model = User::findOne(['id' => 1]);

this will return all the column from the table with user id equal 1, but suppose i just want to get only username and email from this column how do i write the query with active record, i tried the below code but it wont work..`

$model = User::find('username','email')->where('id'=1)
like image 884
sam Avatar asked May 20 '16 03:05

sam


People also ask

How to select only certain cells in a column in Excel?

Highlight the column that you want to select the certain cells. 2. Click Data > Filter, see screenshot: 3. And a small triangle will display at the bottom right corner of the title, click the small triangle, and a menu will appear. Choose Number Filter > Custom Filter …

How to select multiple columns along with a condition in SQL?

When we have to select multiple columns along with some condition, we put a WHERE clause and write our condition inside that clause. It is not mandatory to choose the WHERE clause there can be multiple options to put conditions depending on the query asked but most conditions are satisfied with the WHERE clause.

How to select cells based on certain criteria in Excel?

Select cells based on certain criteria with Kutools for Excel. After setting the criteria, click OK or Apply button, a prompt message will remind you the number of the selected cells. And all of cells which accord with the criteria have been selected from the range.

How to create conditional formatting only cells with specific criteria in Excel?

1. Select the data range that you want to use. 2. Click Home > Conditional Formatting > New Rule, see screenshot: 3. In the New Formatting Rule dialog box, select Format only cells that contain option under Select a Rule Type, and then specify the criteria you need under Format the Rule Description, see screenshot:


1 Answers

$model = User::find()
       ->select(['column1', 'column2'])
       ->where(['id' => $id])
       ->one();
like image 61
0xdenishdev Avatar answered Sep 18 '22 19:09

0xdenishdev