我试图选择一件用户尚未投票的t恤衫(从另一个“投票”表中)
“提交”是一张有T恤的桌子
“投票”是一张有投票权的桌子
“vots”结构是:ID,TEE,USER(其中vots.TEE==submissions.ID)
这是我正在尝试的mysql语句:

SELECT
  submissions.name,
  submissions.id,
  submissions.uploader,
  submissions.image_vote
 FROM
  submissions,votes
 WHERE
  submissions.date_voted IS NOT NULL AND
  submissions.id NOT IN (SELECT tee FROM votes WHERE tee=submissions.id AND user='3')
 LIMIT 1

根据我的理解,我不能使用“tee=submissions.id”,因为它来自这个子查询之外的查询。那么我该如何通过子查询来传递我正在检查的t恤的ID呢?
谢谢您。

最佳答案

你试过这个吗:

SELECT
  submissions.name,
  submissions.id,
  submissions.uploader,
  submissions.image_vote
 FROM
  submissions,votes
 WHERE
  submissions.date_voted IS NOT NULL AND
  submissions.id NOT IN (SELECT tee FROM votes WHERE user='3')
 LIMIT 1

也许不是最有效的,但尽可能接近你的想法。

10-07 17:56