When writing fuzzy queries today, when sorting by time and paging, there is an SQL statement in the MyBatis mapping file
1 SELECT2 <Include refID="Base_column_list"/>3 from USERU4 WHEREU.status!=#{status,jdbctype=VARCHAR}5 <ifTest="Keyword!= NULL andKeyword!= "'">6 and7 (8U.name like#{keyword,jdbctype=VARCHAR}9 ORU.username like#{keyword,jdbctype=VARCHAR}Ten ) One </if> A ORDER byU.lastupdateddateDESC -LIMIT #{offsetnum},#{pagesize}
If you sort and then page through, you can get the results you want, but instead
SELECT <Include refID="Base_column_list"/> from USERUWHEREU.status!=#{status,jdbctype=VARCHAR} <ifTest="Keyword!= NULL andKeyword!= "'"> and(U.name like#{keyword,jdbctype=VARCHAR} ORU.username like#{keyword,jdbctype=VARCHAR} ) </if>LIMIT #{offsetnum},#{pagesize}ORDER byU.lastupdateddateDESC
If you do, you will get an error. The order in which SQL is executed is from where select. Can I think of the Where condition in the same priority who is in front of the priority execution, and the order is the sort of query results, and the limit is the selective acquisition of the query results;
The results are sorted again, and the result should be related to the work mechanism of order by. According to the above examples, it is obvious that the results can be selectively obtained after sorting. If Bo friends can post official document explanation, thank you very much ~
MySQL Limit ORDER BY