Mysql show offset with query

I have some data in my database

---------
| Name  | Offset(only for imagine it)
---------
| Aa    | 1
| Ab    | 2
| Ba    | 3
| Cf    | 4
| As    | 5
---------

      

when using this query

SELECT * FROM table LIMIT 1,3;

      

the first 3 data should be shown, Aa, Ab, Ba, with an offset like this. Now I want to select all name prefixed with a, so use this query

SELECT * FROM table WHERE Name LIKE 'a%' LIMIT 1,3;

      

I want to show the result of this query with an offset, how do I do that? Loop is not the solution I want.

---------
| Name  | Offset(only for imagine it)
---------
| Aa    | 1
| Ab    | 2
| As    | 5
---------

      

Any help is appreciated Thanks!

+3


source to share


1 answer


You have it mostly correct. However, the lines start at 0. So the answer is SELECT * FROM table

WHERE Name LIKE 'a%' LIMIT 0.3

This SQL query will select everything in the table of the table that starts with the letter "a" (or "A").



In alphabetical order, use ORDER BY Name.

0


source







All Articles