dimanche 23 juillet 2017

How to extract all rows which is duplicates in laravel?

I want to get all rows which is the same name and location from Users Table

**id** |name        |location    |phone_number

1      |John        | Europe     |0988884434

2      |john        | Europe        |0933333333

3      |Michael     |Europe      |0888888888

4      |Smith       |Dubai       |082388888888

5      |Smith       |Dubai      | 03939494944

I want to get all rows which is the same name and location like

john  |Europe

john  |Europe

Smith |Dubai

Smith |Dubai

here is how i tried to do

$duplicates = DB::table('users')
->select('name','location', DB::raw('COUNT(*) as `count`'))
->groupBy('name', 'location')
->having('count', '>', 1)
->get();

but this is just showing only one row which is duplicates like

john |Europe
Smith|Dubai

Any help or advice you have would be greatly appreciated.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire