Welcome Guest, Not a member yet? Register   Sign In
Table short name and queries
#7

(11-08-2022, 04:46 PM)kenjis Wrote: It is not a super easy query.
I don't know how to properly write it in Model.

If you really like to use an alias, it seems better to extend Model to add $alias property.

If you use Query Builder, something like this:
PHP Code:
$db      = \Config\Database::connect();
$builder $db->table('news n');
$builder->select('n.id, n.title, n.created_at, n.is_active, u.firstname')
    ->join('users u','news.createdby_id = u.id','left')
    ->orderBy('is_active DESC, title ASC');
$query $builder->get(); 

See https://codeigniter4.github.io/CodeIgnit...r.html#get

Ok, thanks for taking a look.

My comment about it being super simple I guess was in reference to others that I have with 3 joins and 2 sub-selects with grouping and sorting (for instance)! Smile
Reply


Messages In This Thread
Table short name and queries - by SoccerGuy3 - 11-07-2022, 04:37 PM
RE: Table short name and queries - by kenjis - 11-07-2022, 04:53 PM
RE: Table short name and queries - by SoccerGuy3 - 11-07-2022, 05:36 PM
RE: Table short name and queries - by kenjis - 11-07-2022, 06:00 PM
RE: Table short name and queries - by SoccerGuy3 - 11-08-2022, 09:49 AM
RE: Table short name and queries - by kenjis - 11-08-2022, 04:46 PM
RE: Table short name and queries - by SoccerGuy3 - 11-08-2022, 04:50 PM
RE: Table short name and queries - by davis.lasis - 11-09-2022, 12:30 AM
RE: Table short name and queries - by SoccerGuy3 - 11-09-2022, 05:25 PM
RE: Table short name and queries - by kenjis - 11-09-2022, 12:37 AM
RE: Table short name and queries - by SoccerGuy3 - 11-10-2022, 08:56 AM
RE: Table short name and queries - by kenjis - 11-10-2022, 06:42 PM
RE: Table short name and queries - by SoccerGuy3 - 11-11-2022, 07:18 AM



Theme © iAndrew 2016 - Forum software by © MyBB