hello everyone I ask for help to understand how to proceed with the sql code I have a table set as in the photo
in the kiss_count cell do duplicates in the records, see photos. how can I retrieve records for example from 6 onwards? I tried to do something like this, but it doesn't respect the list, skip kiss_count 6 and go directly to 2, the problem is that there are duplicates like 6 6 or 11, how can I proceed? I could lean on the id list to respect the calls in the right irdine, the code that yso is this:
WHERE kiss_count < '6' ORDER BY kiss_count_total DESC LIMIT 5");
the question is can I order a list with duplicates?
I have also tried this
WHERE kiss_count < '6' AND ID < '8' ORDER BY kiss_count_total DESC LIMIT 5");
BUT IT DOES NOT WORK
It is skipping 6 because it searching for kiss_count < 6
. You should check for kiss_count <= 6
WHERE kiss_count <= '6' ORDER BY kiss_count_total DESC LIMIT 5");
So you want to order the kiss_count
field which has duplicates. To do this you need to use an extra field. Reading the title, you also want to be able to get the next 5 values.
You can use the order by
on 2 columns, no need for the where
clause:
select * from my_table order by kiss_count desc, id asc;
Because the query select * from my_table order by kiss_count desc, id asc
always gives you the same sequence, you can grap results using offset
.
So in your example, the second page should have an offset
of 5, and a row_count
of 5:
// page 2
select * from my_table order by kiss_count desc, id asc limit 5, 5;
// page 3
select * from my_table order by kiss_count desc, id asc limit 10, 5;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.