SELECT
id, title, sort
FROM
my_table
WHERE
id = 1 AND
SELECT id, title
FROM my_table
WHERE sort is > *sort from first select*
LIMIT 1.
我正在尝试从我的表中选择一行,然后根据第一个选择的内容选择另一行,我可以这样做吗?或者它必须是两个查询?
基本上,我正在尝试选择id为1的行,然后获取它的排序值,然后找到上面有下一个排序值的行。
答案 0 :(得分:1)
你可以这样做但是在一行中检索它:
SELECT *
FROM my_table t1
JOIN my_table t2 ON (t2.sort>t1.sort)
WHERE t1.title="something you like"
ORDER BY t2.sort DESC LIMIT 1;
答案 1 :(得分:0)
这就是我的建议:
SELECT id, title, sort
FROM my_table
WHERE sort > (SELECT sort
FROM my_table
WHERE id = 1)
答案 2 :(得分:0)
最简单的方法是
SELECT t1.id as Table1_id , t1.title as Table1_title ,
t1.sort as Table1_sort , t2.id as Table2_id, t2.title as Table2_title
FROM my_table t1 , my_table t2
WHERE t1.id = 1 AND t2.sort > t1.sort
LIMIT 1.
这将产生您想要的输出。