Laravel - Get the last entry of each UID type

后端 未结 6 2008
栀梦
栀梦 2020-11-30 15:46

I have a table that has 100\'s of entries for over 1000 different products, each identified by a unique UID.

ID  UID                 MANY COLUMNS    CREATED          


        
6条回答
  •  广开言路
    2020-11-30 16:42

    SOLVED

    Thanks to Tim and M Khalid for their replies. It took me down the right road but I hit a snag, hence why I am posting this solution.

    This worked:

            $allRowsNeeded = DB::table("table as s")
                ->select('s.*')
                ->leftJoin("table as s1", function ($join) {
                    $join->on('s.uid', '=', 's1.uid');
                    $join->on('s.created_at', '<', 's1.created_at');
                })
                ->whereNull('s1.uid')
                ->get();
    

    However I got an Access Violation so I had to go in to config/database.php and set

    'strict' => false,
    

    inside the 'mysql' config, which removes ONLY_FULL_GROUP_BY from the SQL_MODE.

    Thanks again.

提交回复
热议问题