How to retrieve all records after one with an ID in symfony?

后端 未结 2 793
南方客
南方客 2021-01-24 04:40

Let\'s say I have a table that I sort alphabetically in symfony. Each item has a rather random id and I\'d like to retrieve all items after a certain ID. For example:

         


        
相关标签:
2条回答
  • 2021-01-24 05:00
    SELECT *
    FROM tbl1
    WHERE name > (
      SELECT name
      FROM tbl1
      WHERE id = 3
    )
    ORDER BY name
    

    (runs at least with Postgres and with Just Aguy's SQL Fiddle)

    0 讨论(0)
  • 2021-01-24 05:02

    Here is a SQLFiddle that shows this working. The query is simple, just do some matching on the first letter. I don't like the idea of the hardcoded value of 3 being there. Is there a process that's going to set the value of the id?

        select name from tbl1 
        where (Left(name,1)) > (select Left(name,1) 
                            from tbl1 where id = 3)
        order by name asc
    
    0 讨论(0)
提交回复
热议问题