简化嵌套查询

时间:2020-10-17 00:47:39

标签: mysql sql subquery inner-join relational-algebra

select name 
from person, author, article
where name != "John Doe" AND
      person.pid = author.pid AND
      author.aid = article.aid AND
        title = select title
                from author, person, article
                where person.name = "John Doe" AND
                      author.pid = person.pid AND
                      article.aid = author.aid

上面是我在sqlite中为关系代数编写的嵌套查询,该关系代数输出与John Doe共同撰写文章的人员的姓名。

这是关系模式:
文章(帮助,标题,年份,知己,页码)作者(帮助,pid)人(pid,名称,隶属关系)。
我的问题是如何简化嵌套查询?

1 个答案:

答案 0 :(得分:1)

我完全看不到您的问题与正则表达式的关系。但是,如果您需要与John Doe共同撰写的人员的姓名,我建议加入:

condition_variable::wait()

查询始于人John Doe,并将相应的行带入select distinct pe2.name from person pe1 inner join author au1 on au1.pid = pe1.pid inner join author au2 on au2.aid = au1.aid and au2.pid <> au1.pid inner join person pe2 on pe2.pid = au2.pid where pe1.name = 'John Doe' 中;然后,它将搜索所有共同作者,最后带上他们的名字。

相关问题