Home > Mobile >  Initializing offset from column containing string in mysql
Initializing offset from column containing string in mysql

Time:06-17

I want to get the data after the row with a certain string. I think I will explain it better with the following example. Below is a mysql table.

-id- -name(unique)-
 1    Test 
 2    Test2
 3    Test3
 4    Test4

Here, for example, I want to get the data after the row with the name 'Test2'. Is it possible to do this in one query with mysql? (By pulling the id of the row with that data and not using it as an offset.)

It should give the following result as a result.

-id- -name-
 3    Test3
 4    Test4

I searched but couldn't find it or I couldn't understand how to search. Can you help?

CodePudding user response:

You basically need to use LIMIT and OFFSET. Since you don't know the number of rows you want to have in you result, you can set limit to a high number. Something like

SELECT * FROM TABLE1 t LIMIT 9999999999 OFFSET 2

OFFSET value can be set to whatever the number of rows you want to exclude from your result.

Or as per your question if you don't want to use OFFSET, use a subquery to determine the id

SELECT * FROM TABLE1 t WHERE t.id>(SELECT t1.id FROM TABLE1 t1 WHERE t1.name='Test2')
  • Related