SQL Query to Select the 'Next' record (similar to First or Top N)
问题 I need to do a query to return the next (or prev) record if a certain record is not present. For instance consider the following table: ID (primary key) value 1 John 3 Bob 9 Mike 10 Tom. I'd like to query a record that has id 7 or greater if 7 is not present. My questions are, Are these type of queries possible with SQL? What are such queries called in the DB world? Thanks! 回答1: Yes, it's possible, but implementation will depend on your RDBMS. Here's what it looks like in MySQL, PostgreSQL