I have one MYSQL query with me I want to execute this query in laravel.
select d1.update_id from ( select update_id, count(update_id)
as ct from updates_tags where tag_id in
(67,33,86,55) group by update_id) as d1 where d1.ct=4
Please guide me how do i Do it easily.
I have one reference with me.... It is not working
$updateArray = DB::table('updates_tags')
->select('update_id', DB::raw('count(*) as update_id'))
->whereIn('tag_id',$jsontags)
->groupBy('update_id')
->having('update_id','=',count($jsontags))
->lists('update_id');
You can just do a RAW query. like this:
$sqlQuery = "SELECT d1.update_id FROM...";
$result = DB::select(DB::raw($sqlQuery));
the $result will be an array
change the where('total','=',count($tags)) to having('total','=',count($tags))
$update = DB::table('tags')
->select('t_id', 'u_id', DB::raw('count(*) as total'))
->whereIn('t_id',$tags)
->groupBy('u_id')
->having('total','=',count($tags))
->lists('u_id');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With