Select specific MySQL rows

How can I select specific rows in a MySQL table? So, instead of selecting, ... ORDER BY datecan I do something like SELECT * FROM Posts FROM(5) TO(10) ORDER BY date DESCwhere I would select Posts 5 to 10 in descending order?

+3
source share
6 answers

Your question is a bit ambiguous. Two possibilities are possible:

  • You want to get only a part of the results from the database, for example, from the 5th to the 10th:

    SELECT * FROM `posts` ORDER BY `date` DESC LIMIT 6 OFFSET 4
    

    which will skip the first 4 results and give you the next 6 results (starting from the 5th from the original set and ending with the 10th from the original set).

  • You need results with specific identifiers between 5(inclusive) and 10(inclusive):

    SELECT * FROM `posts` WHERE `id` BETWEEN 5 AND 10 ORDER BY `date` DESC
    

    ( , ):

    SELECT * FROM `posts` WHERE `id` IN (5,6,7,8,9,10) ORDER BY `date` DESC
    

    - "" .

+10

:

SELECT * FROM Posts ORDER BY date DESC LIMIT 5, 5

http://php.about.com/od/mysqlcommands/g/Limit_sql.htm

+3

, , :

SELECT * FROM Posts ORDER BY date DESC LIMIT 5 OFFSET 5

, , .

LIMIT 5,5, .

+1

limit mysql . : SELECT * FROM posts LIMIT 5 , 5;

0

:

SELECT * FROM tabel ORDER BY date DESC LIMIT 5,5 

( 5- 10- , ).

-1
SELECT * FROM Posts ORDER BY date DESC limit 5, 10
-2

All Articles