我试图从连接中获取随机记录,但我无法让它工作!有任何想法吗?它使用的是Microsoft Access 2003。
table = members
===============
memberID int
name varchar
table = testimonials
====================
testimonialID int
memberID int
content memo
select m.*, (SELECT t.content from testimonials t where t.memberID=m.memberID ORDER BY rnd(t.testimonialID)) as testimonialtext
FROM members m;
我基本上需要每个成员记录和该成员的一个随机证明。我还应该补充一点,我已经在加入中尝试过了......
select m.*, t.content FROM members m
INNER JOIN testimonials t ON m.memberID=t.memberID
ORDER BY rnd(t.testimonialID)
感谢您的帮助。
答案 0 :(得分:0)
尝试用TOP子句限制
select m.*, (SELECT top 1 t.content from testimonials t where t.memberID=m.memberID ORDER BY rnd(t.testimonialID)) as testimonialtext
FROM members m;
好的,那么我们可以做类似的事情:
select
m.*,
t3.content
FROM
members m,
(select
top 1 t.testimonialID,
from
testimonials t
where
t.memberID=m.memberID
order by
rnd(t.testimonialID)
) t2,
testimonials t3
where
t3.testimonialID = t2.testimonialID;