此查询未运行..请解决此问题..
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
此查询未运行..请解决此问题..
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
您的查询没有问题。我打赌它会运行但结果错误。您正在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
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';
不要使用旧的 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
您需要做的是在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