Redian新闻
>
Any faster way to retrieve only one record?
avatar
Any faster way to retrieve only one record?# Database - 数据库
p*3
1
【艺码当先】书法作品 3-鹏程万里
avatar
n*u
2
Sorry to bother high hands again. Thanks for your help before!
Table a, articleid (pk), userid, datetime, textbody
Table b, userid (pk), nickname
I want one record, that's the latest article, with nickname, datetime and
textbody.
So I wrote this:
SELECT a.DateTime,b.Nickname,a.textbody
FROM a, b
WHERE a.userid=b.userid
ORDER BY datatime DESC
LIMIT 0, 1
But I feel this might be slow. Any way to make it fast?
I told my team leader we should write this as a stored procedure, but he
refused.
avatar
q*x
3
赞!
背景那个四个圈圈是纸的装饰,还是用来方便控制字体大小的啊?
avatar
c*d
4
1. create index on table_a (datetime)
2. select ... from a, b where a.userid=b.userid and a.datetime=(select max(d
atetime) from a

【在 n****u 的大作中提到】
: Sorry to bother high hands again. Thanks for your help before!
: Table a, articleid (pk), userid, datetime, textbody
: Table b, userid (pk), nickname
: I want one record, that's the latest article, with nickname, datetime and
: textbody.
: So I wrote this:
: SELECT a.DateTime,b.Nickname,a.textbody
: FROM a, b
: WHERE a.userid=b.userid
: ORDER BY datatime DESC

avatar
p*3
5
谢谢MM,内行啊, 您说的很对。背景那个四个圈圈是纸的装饰, 同时又是用来方便控制
字体大小.

【在 q**x 的大作中提到】
: 赞!
: 背景那个四个圈圈是纸的装饰,还是用来方便控制字体大小的啊?

avatar
n*6
6
未经测试。
SELECT a.articleid, ...., max(a.datetime), ...
FROM a, b
WHERE a.userid = b.userid

【在 n****u 的大作中提到】
: Sorry to bother high hands again. Thanks for your help before!
: Table a, articleid (pk), userid, datetime, textbody
: Table b, userid (pk), nickname
: I want one record, that's the latest article, with nickname, datetime and
: textbody.
: So I wrote this:
: SELECT a.DateTime,b.Nickname,a.textbody
: FROM a, b
: WHERE a.userid=b.userid
: ORDER BY datatime DESC

avatar
f*n
7
我更喜欢左边的题字,嘻嘻
avatar
c*d
8
your solution only works when "select max(a.datetime)"
in his case, he needs more than 1 column with aggregate columns

【在 n********6 的大作中提到】
: 未经测试。
: SELECT a.articleid, ...., max(a.datetime), ...
: FROM a, b
: WHERE a.userid = b.userid

avatar
n*u
9
Thanks, it did improve the query speed. Cut off time more than 50%!
avatar
B*g
10
回贴没原文. what is "it"?

【在 n****u 的大作中提到】
: Thanks, it did improve the query speed. Cut off time more than 50%!
avatar
c*d
11
肯定是我那个
另外一个语法就不work

【在 B*****g 的大作中提到】
: 回贴没原文. what is "it"?
avatar
n*u
12
using max(datetime), hehe

【在 B*****g 的大作中提到】
: 回贴没原文. what is "it"?
avatar
c*d
13
两个都用了max(datetime)

【在 n****u 的大作中提到】
: using max(datetime), hehe
avatar
B*g
14
其实我想问有没有create index。

【在 c*****d 的大作中提到】
: 肯定是我那个
: 另外一个语法就不work

avatar
n*u
15
Thanks! The query really speeds up a lot!

【在 c*****d 的大作中提到】
: 肯定是我那个
: 另外一个语法就不work

avatar
n*u
16
I tried his code w/o creating index. it's fast
but after I created index, it's slow.

【在 B*****g 的大作中提到】
: 其实我想问有没有create index。
avatar
B*g
17
hehe.

【在 n****u 的大作中提到】
: I tried his code w/o creating index. it's fast
: but after I created index, it's slow.

avatar
c*d
18
嗯,为什么这样,不make sense呀?

【在 B*****g 的大作中提到】
: hehe.
avatar
n*u
19
I will take a look at that. Maybe I mess up something... hehe

【在 c*****d 的大作中提到】
: 嗯,为什么这样,不make sense呀?
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。