Laravel 5.5 - Get specific row in duplicate row

Let's say i have a user table like this :

+----+-----------+---------+------------+------+
| ID | Name | Email | Age |
+----+-----------+---------+------------+------+
| 1 | John | john.doe1@mail.com | 24 |
| 2 | Josh | josh99@mail.com | 29 |
| 3 | Joseph | joseph410@mail.com | 21 |
| 4 | George | gge.48@mail.com | 28 |
| 5 | Joseph | jh.city89@mail.com | 24 |
| 6 | Kim | kimsd@mail.com | 32 |
| 7 | Bob | bob.s@mail.com | 38 |
| 8 | Joseph | psa.jos@mail.com | 34 |
| 9 | Joseph | joseph.la@mail.com | 28 |
| 10 | George | georgj04@mail.com | 22 |
+----+-----------+---------+------------+------+

In the actual, it have more data and some of them is duplicated with more than two record, but the point is i want to get the first and the second row that have name "Joseph", but how to do it ? My code this far...

User::withTrashed()->groupBy('name')->havingRaw('count("name") >= 1')->get();

With that code the result will retrieve :

| 3  | Joseph    | joseph410@mail.com   | 21   |

And i use this code to try to get the second duplicate row :

User::withTrashed()->groupBy('name')->havingRaw('count("name") >= 2')->get();

The result still same as the mentioned above :

| 3  | Joseph    | joseph410@mail.com   | 21   |

I want the result is to get record that have the id "5" with name "Joseph", can anybody give me suggestion ?



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3b5x6H6
via IFTTT

تعليقات

المشاركات الشائعة من هذه المدونة

I am unable to figure out how to create payment collection request, after a form has been submitted in laravel

laravel, mysql transaction not working after failed one time