Eloquentで結合後、指定キーで重複していたら最新の日付で重複を無くしたい
・laravel8
・Eloquent
下記のようなテーブルがあります。
sam1
id | data1 | data2 |
---|---|---|
1 | text | text |
2 | text | text |
: | : | : |
sam2
id | sam1.id | specific_date |
---|---|---|
1 | 1 | 2022/01/01 |
2 | 1 | 1990/01/01 |
3 | 1 | 2020/01/01 |
4 | 2 | 1990/01/01 |
5 | 2 | 1890/01/01 |
6 | 2 | 2022/10/10 |
: | : | : |
実現したいこと
結合後
id | sam1.id | data1 | data2 | specific_date |
---|---|---|---|---|
1 | 1 | text | text | 2022/01/01 |
6 | 2 | text | text | 2022/10/10 |
: | : | : | : | : |
※1 sam1.idを重視したくない
【specific_date】の最新の日付で重複(※1)を無くしたい。
説明下手なので不明点等は随時追記していきますので宜しくお願い致します。
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。