MS Access 2003 连接内的随机记录

发布于 2024-11-28 23:33:01 字数 596 浏览 1 评论 0原文

我试图从连接中获取随机记录,但我无法让它工作!有什么想法吗?它使用 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)

感谢您的帮助。

I am trying to get a random record from a join, but I cannot get it to work! Any ideas? It's using 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;

I basically need each member record and one random testimonial for that member. I should also add that I've tried it within a join too...

select m.*, t.content FROM members m
INNER JOIN testimonials t ON m.memberID=t.memberID
ORDER BY rnd(t.testimonialID)

Thanks for any help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

戏舞 2024-12-05 23:33:01

尝试用 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;

try to limit with TOP clause

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;

ok, then we can do something like:

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;
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文