0

此查询未运行..请解决此问题..

select q.id,q.name,qq.text 
from quiz q,quiz_question qq 
where qq.quiz_id='1'

桌子:

quiz
   id,name
quiz_question
   id,quiz_id,text
4

4 回答 4

2

您的查询没有问题。我打赌它会运行但结果错误。您正在cross 加入表格。我想你想要:

select q.id, q.name, qq.text 
from   quiz q,quiz_question qq 
where qq.quiz_id = '1' AND
      q.id=qq.quiz_id

最好这样做

select q.id, q.name, qq.text 
from   quiz q INNER JOIN quiz_question qq 
           on q.id=qq.quiz_id
where  qq.quiz_id = '1'

还有一件事,如果你的id是,number那么你不应该用单引号括起来。

select q.id, q.name, qq.text 
from   quiz q INNER JOIN quiz_question qq 
           on q.id=qq.quiz_id
where  qq.quiz_id = 1
于 2012-07-20T08:02:35.457 回答
1
select q.id,q.name,qq.text 
from quiz q inner join quiz_question qq on q.id = qq.quiz_id
where q.quiz_id='1';

或者

select q.id,q.name,qq.text 
from quiz q inner join quiz_question qq on q.id = qq.quiz_id and q.quiz_id='1';
于 2012-07-20T08:06:33.380 回答
0

不要使用旧的 SQL 语法。如果要连接表,请使用显式join

select q.id, q.name, qq.text 
from quiz q
inner join quiz_question qq on q.id = qq.quiz_id
where q.id = 1
于 2012-07-20T08:04:25.533 回答
0

您需要做的是在quiz_id.

这可以这样做:

 SELECT
  q.id,q.name,
  qq.text
 FROM
  quiz q
  INNER JOIN quiz_question qq ON ( q.id = qq.quiz_id )
 WHERE
  q.id = 1
于 2012-07-20T08:07:08.233 回答