user3789803
user3789803

Reputation: 43

How do I code this SQL query in Laravel? Correct way to code mySQL HAVING

The SQL statement below returns the right result, however I am having trouble converting this to Laravel and finding the right way to code Count(*) >=2 .

SELECT  `column_id` 
FROM  `table` 
WHERE  `game_id` 
IN ( 13, 14 ) 
GROUP BY  `column_id` 
HAVING COUNT( * ) >=2

Upvotes: 1

Views: 46

Answers (1)

Javi Stolz
Javi Stolz

Reputation: 4755

Use havingRaw()

DB::table('table')
->select('column_id')
->whereIn('game_id', array(13, 14))
->groupBy('column_id')
->havingRaw('COUNT(*) >=?', array(2))
->get();

Upvotes: 1

Related Questions