如何解决Mysql 按上一个表列限制连接表结果
我有三个表:test_composite
、tests
、questions
。 TestComposite 属于 Test。测试有很多问题。
create table test_composite
(
id bigint unsigned auto_increment
primary key,id_include_test bigint unsigned not null,questions_quantity smallint unsigned not null,)
create table tests
(
id bigint unsigned auto_increment
primary key,name varchar(128) not null,)
create table questions
(
id bigint unsigned auto_increment
primary key,question text not null,test_id bigint unsigned not null,)
问题是如何使这个查询工作:
select questions.*
from test_composite
inner join tests on test_composite.id_include_test = tests.id
inner join questions on questions.id in (
select id
from questions
where tests.id = questions.test_id limit test_composite.questions_quantity
);
此查询应连接 test_composite
和 tests
表,然后连接具有限制范围的问题。因此,一切都取决于在当前表查询中使用以前的表数据。
问题是不允许使用 limit test_composite.questions_quantity
。
有什么办法吗?
附注。 Mysql 5.6 版本。
我对横向连接有一点了解,但在 5.6 版本中不支持。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。