Home Count duplicate columns in Laravel
Reply: 0

Count duplicate columns in Laravel

user1076
1#
user1076 Published in July 23, 2018, 1:36 pm

How do you count the DUPLICATE columns in a database table using eloquent model querying?

For example, in SQL, there's this command:

SELECT name, COUNT(email) 
FROM users
GROUP BY email 
HAVING ( COUNT(email) > 1 )

The code above will return the names from all columns with similar email addresses.

What I'm trying to achieve is to get the COUNT of duplicate entries, i.e.

$noOfjobsFromSameCustomers = App\Workflow::count();

But I need an additional parameter to specify that the cust_id (a column in the workflows table) is duplicated, something like:

$noOfjobsFromSameCustomers = App\Workflow::notDistinct()->orderBy('cust_id')->count();

For example, given the table below:

 ID  NAME EMAIL 
 1   John asd@asd.com 
 2   Sam  asd@asd.com 
 3   Tom  asd@asd.com 
 4   Bob  bob@asd.com 
 5   Tom  asd@asd.com 

How can I count the number of times a specified email address (e.g. asd@asd.com) recurs?

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.329168 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO