Hello i need a query to transform to laravel query or laravel raw query better.....its complex and im strunggling 2 days now i cant do it ::(
SELECT TOP (10) Home_LogStudents.LogSt_data, Home_LogStudents.LogSt_date, Home_LogStudents.LogSt_studid, Home_Students.home_firstname
FROM Home_LogStudents
INNER JOIN Home_Students
ON Home_LogStudents.LogSt_studid = Home_Students.home_id
WHERE (Home_LogStudents.LogSt_action = 225)
AND (Home_LogStudents.LogSt_sectionID = 257)
AND (Home_LogStudents.LogSt_date IN
(SELECT MIN(LogSt_date) AS Expr1
FROM Home_LogStudents AS Home_LogStudents_1
WHERE (LogSt_data <> '0')
AND (LogSt_action = 225)
AND (LogSt_sectionID = 257)
AND (LogSt_studid IN
(SELECT Home_Students_1.home_id
FROM Hw_StudentClasses
INNER JOIN Home_Students AS Home_Students_1
ON Home_Students_1.home_studid = Hw_StudentClasses.Stclass_studid
WHERE (Hw_StudentClasses.Stclass_classid = 98)))
GROUP BY LogSt_studid))
ORDER BY Home_LogStudents.LogSt_data DESC
All i could do is this and its not working a lot of errors.....
$users = DB::Table('Home_LogStudents')
->select('LogSt_data','LogSt_date','LogSt_studid')
->where('LogSt_action','=',225)
->where('LogSt_sectionID','=',$id)
->whereIn('LogSt_date',function($query) use ($id, $class_id)
{
return $query = DB::Table('Home_LogStudents')
->min('LogSt_date')
->where('LogSt_data','!=',0)
->where('LogSt_action','=',225)
->where('LogSt_sectionID','=',$id)
->whereIn('LogSt_studid',function($query) use ($id, $class_id)
{
return $query = DB::Table('Hw_StudentClasses')
->select('home_id')
->join('Home_Students','Home_Students.home_studid','=','
Hw_StudentClasses.Stclass_studid')
->where('Stclass_classid','=',$class_id);
})
->groupBy('LogSt_date');
})
->orderBy('LogSt_data','DESC')
->get();
Thanks all for only looking.....its too complicate for my knowlegde
I FOUND THE ASWER really it was so easy !
$users = DB::select('SELECT TOP (10) Home_LogStudents.LogSt_data, Home_LogStudents.LogSt_date, Home_LogStudents.LogSt_studid, Home_Students.home_firstname, Home_Students.home_lastname
FROM Home_LogStudents
INNER JOIN Home_Students
ON Home_LogStudents.LogSt_studid = Home_Students.home_id
WHERE (Home_LogStudents.LogSt_action = 225)
AND (Home_LogStudents.LogSt_sectionID = '.$id.')
AND (Home_LogStudents.LogSt_date IN
(SELECT MIN(LogSt_date) AS Expr1
FROM Home_LogStudents AS Home_LogStudents_1
WHERE (LogSt_data <> \'0\')
AND (LogSt_action = 225)
AND (LogSt_sectionID = '.$id.') AND (LogSt_studid IN
(SELECT Home_Students_1.home_id
FROM Hw_StudentClasses INNER JOIN
Home_Students AS Home_Students_1
ON Home_Students_1.home_studid = Hw_StudentClasses.Stclass_studid
WHERE (Hw_StudentClasses.Stclass_classid = ' .$class_id.')))
GROUP BY LogSt_studid))
ORDER BY Home_LogStudents.LogSt_data DESC
');
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community