M
M
Max Khrichtchatyi2015-01-06 08:32:48
MySQL
Max Khrichtchatyi, 2015-01-06 08:32:48

Why doesn't ORDER BY FIELD() & LIMIT 0.10 / 10.10 work?

There is a table of 2 fields from which I pull records using sorting
ORDER BY FIELD('3', '0', '1', '2') LIMIT 0, 10

id	status
1234	3
1235	3
1231	0
1240	0
1239	0
1238	0
1237	0
1236	0
1257	0
1242	0

after I want to see the next 10 records
ORDER BY FIELD('3', '0', '1', '2') LIMIT 10, 10
id	status
1243	0
1242	0
1241	0
1240	0
1239	0
1238	0
1237	0
1236	0
1257	0
1252	0

here the entries are repeated, how to organize pagination in this case?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
Y
yttrium, 2015-01-11
@yttrium

SELECT id, status
FROM (
  SELECT id, status
  FROM table
  ORDER BY FIELD(status, '3','0','1','2')
  ) as t
LIMIT 10 OFFSET 10

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question