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

704

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:

Name      ID

Let's say I wanted to retrieve{-code-2} and{-code-3}. I know beforehand of the ID 3 and that I want everything after it.

How should I construct the statements to achieve this?

I don't care if the answer uses Propel, MySQL, SQL, or whatever. As long as it's possible.

193

Answer

-- Apple 5 Banana 9 Coconut 3 Date 1 Eggplant 8|||Date|||Eggplant
789

Answer

Solution:

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)

477

Answer

Solution:

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

People are also looking for solutions to the problem: memory - How do I tell PHP to get rid of load_file data after it's used?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.