如何检索一个在symfony中具有ID的记录后的所有记录? [英] How to retrieve all records after one with an ID in symfony?

查看:83
本文介绍了如何检索一个在symfony中具有ID的记录后的所有记录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

比方说,我有一张桌子,我用symfony按字母顺序对其进行排序.每个项目都有一个相当随机的ID,我想在某个ID之后检索所有项目.例如:

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
------------
Apple     5
Banana    9
Coconut   3
Date      1
Eggplant  8

比方说,我想检索DateEggplant.我事先知道ID 3,并且想要它之后的所有内容.

Let's say I wanted to retrieve Date and Eggplant. I know beforehand of the ID 3 and that I want everything after it.

我应该如何构造语句来实现这一目标?

How should I construct the statements to achieve this?

我不在乎答案是否使用Propel,MySQL,SQL等.只要有可能.

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

推荐答案

SELECT *
FROM tbl1
WHERE name > (
  SELECT name
  FROM tbl1
  WHERE id = 3
)
ORDER BY name

(至少与Postgres和Just Aguy的SQL Fiddle一起运行)

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

这篇关于如何检索一个在symfony中具有ID的记录后的所有记录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆