Simply cant make this work. How do I select a specific row in a table and then get the info of the record just after it. I do not know the study_code for the second row but I have the study_code for the row right before it.
Im trying to use LIMIT and DESC
…row
…row
…row
… I can select this row with study_code
… But I want the study_code of THIS row
…row
…row
$sql = "SELECT * FROM studies WHERE study_code = ? ORDER BY LENGTH(study_code)
DESC, study_code DESC LIMIT 1,2";
Study_code = ? will have a unique value assigned and it will only return one record.
I want to retrieve the next records study_code.
Right now im trying the following but get the below error
select study_code, next_word
from (
select id,
study_code,
lead(study_code) over (order by id) as next_word
from studies
)
where study_code = 'Study_DRW3S1';
error
#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '(order by id) as next_word
from studies
)
where study_code = ‘Study_DRW3S’ at line 5
I have a feeling the entire thing is a case of “Let the receiving language handle it”.
Unless your ID’s are exceedingly large, it would be more compact to simply return id and study_code and let the other end of the request handle the ‘what comes next’.