Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How laravel queries are sorted by whereIn

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article mainly explains "how to sort laravel queries according to whereIn". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn how to sort laravel queries by whereIn.

The example is as follows:

$ids = [5 data 7 ('id',$ids)-> select (' id')-> get (); / / the query result is sorted in the order of wherein / / correctly written $data = Content::whereIn ('id',$ids)-> select (' id') /-> orderBy (\ DB::raw ('FIND_IN_SET (id, ". Implode (", ", $ids). )) / /-> orderBy (DB::raw ("FIND_IN_SET (id,'"). Implode (',', $ids). "'". )) / /-> orderByRaw ("FIND_IN_SET (id,'"). Implode (',', $ids). "'". ')')-> orderBy (\ DB::raw ('FIND_IN_SET (id, ". Implode (", ", $ids). ")")-> get ()

Erroneous writing

/ / incorrectly spelled $data = Content::whereIn ('id',$ids)-> select (' id')-> orderByRaw ('FIND_IN_SET (' id','). Implode (",", $ids) '"."))-> get (); / / the query order is sorted in positive order by id size.

Cause analysis

/ / the sql statement in the correct way is select `id` from `contents`order by FIND_IN_SET (id, "5pje 6pi 7pr 4je 2pl 1") the sql statement incorrectly written by asc// is select `id`from `contents`order by 'FIND_IN_SET (id, "5pje 6pi 7mee 4m 2m 1")' asc// or select `id`from `contents`order by `FIND_IN_SET (id, "5pe 6e 7e 4e 4e 2m 1") `asc// FIND_IN_SET () method do not add any symbols to this I believe you have a deeper understanding of "how laravel queries are sorted according to whereIn". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report