ci_lover
ci_lover

Reputation: 718

how to select column as `another name` in Kohana

I'm using Kohana. I'm trying to select a column as some name but it's giving error - Table 'users AS U' doesn't exist How to make this alias?

 $result = DB::select( 'users.firstname',
                       'users.lastname',
                        'U.firstname AS alt_firstname',
                                   
                       'U.lastname AS alt_lastname'
)
 ->from('mytable')
 ->join('table2', 'INNER')
                ->on('mytable.id', '=', DB::expr('table2.id'))
                ->join('users', 'INNER')
                ->on('users.id', '=', DB::expr('mytable.id'))
                ->join('users AS U', 'INNER')
                ->on('U.id', '=', DB::expr('table2.id'))
                ->execute();
        return $result;

Upvotes: 0

Views: 728

Answers (1)

MisterX
MisterX

Reputation: 310

$query = DB::select(array('username', 'u'), array('password', 'p'))->from('users');

https://kohanaframework.org/3.3/guide/database/query/builder#select-as-column-aliases

Upvotes: 1

Related Questions