需要SELECT *帮助。 [英] SELECT * help needed.

查看:88
本文介绍了需要SELECT *帮助。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




如果我有很多文章,都有唯一的ID。


首先我想搜索那个ID,我能用


SELECT *来自ARTICLE,其中ID = xx


但是我还要展示前后的5篇文章那篇文章。


SELECT *来自ARTICLE,其中ID> xx LIMIT 0,10



来自ARTICLE的SELECT * ID< xx LIMIT 0,10 /

(如果ID是第一个中的一个或者是最后一个中的一个,我选择限制为10,那个方式我总是至少有10篇文章。


是否可以在一个查询中完成上述操作?


我是否应该这样做呢?这会让整个操作变得更快吗

这样做吗?


非常感谢。


Simon

Hi,

If I have a lot of articles, all with a unique IDs.

First I would like to search for that ID, I could do

SELECT * from ARTICLE where ID = xx

But I also want to display the 5 articles before and after that article.

SELECT * from ARTICLE where ID > xx LIMIT 0, 10
and
SELECT * from ARTICLE where ID < xx LIMIT 0, 10

(I choose a limit of 10 in case the ID is one of the first one or one of the
last one, that way I will always have at least 10 articles).

Is it possible to do the above in one single query?

Should I even bother doing that? does it make the whole operation faster to
do it that way?

Many thanks.

Simon

推荐答案

假设你知道xx是什么,还有两个需要的变量是

xx-5和xx + 5


那么

Providing that u know what xx is there two other needed variables are
the xx-5 and xx+5

so then


start =


xx-5;
xx-5;


这篇关于需要SELECT *帮助。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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