I am writing query that return search results from multiple union statements. Query is running fine and results are showing but results are randomly showing. i want them as per some priority. I know how to do it in core php. how can i do this in laravel 5.
SearchController.php :
$first = DB::table('info')
->select('id','name')
->where('name', 'LIKE', $searchstring)
->union($second)
->union($third)
->union($fourth)
->union($fifth)
// ->orderBy('sb')
->get();
i did it using this query in core php
(SELECT '1' as sb, id where name LIKE ? )
union
(SELECT '2' as sb, id, ...)
union
(SELECT '3' as sb, id, ...)
union
(SELECT '4' as sb, id, ...)
union
(SELECT '5' as sb, id, ...) order by sb ";
results are priorities by 'order by sb'. how can I acheive this in laravel?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire