作为简化,我有四个表格,书籍,出版商,作者和公司。图书和出版商均有作者参考,,但该参考文献可为空。SQL从2个不同的表格中选择1个进行优化搜索
我可以通过使用这样的OR连接查询加入作者表来找到作者,但它非常慢。我不得不使用作者表来加入另一个。
模式:
select book.title, author.name, company.name as company_name from book inner join publisher on book.publisher_id = publisher.id inner join author on (book.author_id = author.id OR publisher.author_id = author.id) inner join company on author.company_id = company.id;
我想知道,以优化此查询的最佳方式是什么,而不是对加盟OR条件。谢谢
请在问题 –