Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Initializing offset from column containing string in mysql

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.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

-id- -name-
 3    Test3
 4    Test4

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

>Solution :

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')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading