get next/previous record

SELECT name,
       (SELECT name FROM student s1
        WHERE s1.id < s.id
        ORDER BY id DESC LIMIT 1) as previous_name,
       (SELECT name FROM student s2
        WHERE s2.id > s.id
        ORDER BY id ASC LIMIT 1) as next_name
FROM student s
    WHERE id = 7; 

4.25
4
VTH 120 points

                                    SELECT * FROM foo WHERE id = (SELECT MIN(id) FROM foo WHERE id &gt; 4)

4.25 (4 Votes)
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
find next row in mysql query next row select mysql mysql query next row mysql get next row mysql select from next row result set mysql use the next row in the sql result MYSQL get data from next row how to get next row in mysql in select query how to get next row data in mysql how to check previous id is same or not next id in php get next record using current record query in sql mysql get next field add data from next row in firt mysql mysql get next 10 row mysql return the next minmum mysql return next and prev @prev mysql get immediate previous record in mysql site:stackoverflow.com get immediate previous record in mysql how to select previous record in mysql one by one row come in next and previous link sql get next and previous record get next line record id mysql get next row value select previous row mysql from select mysql get previous row next rcord mysql how to get next and previous id in mysql mysql 5 get previous row mysql query next mysql previous row check if previous record is not the same as next record in java script mysql query to check if previous record not the same as current record mysql query prev next id get prev and next mysql mysql get next id after current record next mysql mysql getting values from row using another item in the row mysql select previous row mysql fetch upcoming recordfs get the next row in smysql get next/previous record get next/previous record in MySQL? get next previous id mysql get next record select sql with condition SQL rebuild index for a table how to select an entire column in mysql mysql query to get the next row
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source