dimanche 23 juillet 2017

How to convert mysql query to query builder for laravel 5?

I am trying to get all duplicates rows from Customers Table I want to convert the following mysql query into query builder to use in laravel 5. And I search in documentation but not luck.

SELECT CustomerName, ContactName, Customers.City FROM Customers INNER JOIN( SELECT City FROM Customers GROUP BY City HAVING COUNT(CustomerName) >1 )temp ON Customers.City= temp.City;

and here I search in google and tried like this , but this query builder is just showing only one row if duplicate.I just want every rows which are duplicates.

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

Any help you have would be greatly appreciated.Thanks.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire