Command to display a record limit in a table

Asked

Viewed 702 times

2

Supposing that a database have a table locacoes, which SQL command would display between the tenth and twentieth record of this table, ordered by the field titulo?

  • 4

    does not let the examiner see the stack open...

  • Take a look at [tour]. You can accept an answer if it solved your problem. You can vote on every post on the site as well. Did any help you more? You need something to be improved?

1 answer

6

SELECT * FROM locacoes ORDER BY titulo LIMIT 9, 10;

I put in the Github for future reference.

It doesn’t have much information but it’s probably this.

In this case does not use the WHERE because you don’t need to filter anything. Use ORDER BY to define the ordering and the LIMIT 9,10 to get the tenth result and the next 10. Use numeric 9 to indicate the initial element because it starts from 0, so if the first is 0 the tenth is 9.

  • You can’t use BETWEEN?

  • 3

    No, the BETWEEN is for something else. It is used in filters (no WHERE for example). It resembles the IN, provided that the data list is a continuous sequence. For example WHERE id BETWEEN 22 AND 27 it would be like doing WHERE id IN (22,23,24,25,26,27). The LIMIT it’s not really a filter, it’s a way of telling which results are relevant to you. It’s a filter after you’ve got the desired result.

  • 1

    It depends on the order of application of the conditions of the question, @bigown applied: sort first, then pick from the 10th to 20th of this list, but what if it is from the 10th to the 20th records in chronological order and these present ordered by the title?

  • 1

    @Jader is, can be interpreted this way, but then the "statement" does not say that it is to take by id, for example :) Would it be between the tenth and twentieth based on what? The way it comes without any criteria? But I think you killed the riddle above :)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.