Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/68.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Sql 通过少量条目获取父记录的更好方法_Sql_Oracle_Plsql_Sqlperformance - Fatal编程技术网

Sql 通过少量条目获取父记录的更好方法

Sql 通过少量条目获取父记录的更好方法,sql,oracle,plsql,sqlperformance,Sql,Oracle,Plsql,Sqlperformance,我的观点代表了出版商和文学(书籍、杂志等)之间的关系 我正在尝试获取发布图书X和出版物Y的出版商id。 例如,要查找正在出版关于事物本质的书籍和出版物的出版商,其结果是出版商id1,5(但不是4) 我将通过内部连接相同的视图来完成此操作: select * from relations publication inner join relations books on publication.publisher_id = books.publisher_id where books.public

我的观点代表了出版商和文学(书籍、杂志等)之间的关系

我正在尝试获取发布图书X和出版物Y的出版商id。
例如,要查找正在出版关于事物本质的
书籍和
出版物的出版商,其结果是出版商id
1,5
(但不是
4

我将通过内部连接相同的视图来完成此操作:

select *
from relations publication
inner join relations books on publication.publisher_id = books.publisher_id
where books.publication_type='Book'
  and books.extended_field_3='Clarissa'
  and publication.publication_type='Publication'
  and publication.extended_field_4='On the Nature of Things'
当我需要通过书籍、出版物、杂志(复杂视图中的3个内部连接)取货时,事情变得复杂起来

有更好的办法吗?(特定于Oracle也有帮助)


我不希望模型使用
extended\u field\u 1
extended\u field\u 4
,但您的查询看起来很好


为每个
扩展的\u字段创建一个单独的字段,作为提高搜索性能的条件。

您使用的是Oracle还是SQL Server?语法建议使用SQL Server.Oracle,语法仅用于示例谢谢。
drop table relations;

CREATE TABLE relations
(
  publisher_id int,
  publication_id varchar(255),
  publication_type varchar(255),
  extended_field_1 varchar(255),
  extended_field_2 varchar(255),
  extended_field_3 varchar(255),
  extended_field_4 varchar(255)  
); 

insert into relations values(1,A,'Book','','','Clarissa','' );  
insert into relations values(1,B,'Publication','','','','On the Nature of Things' );
insert into relations values(1,C,'Book','','','Frankenstein','' );
insert into relations values(3,D,'Book','','','','' );
insert into relations values(3,E,'Publication','','','','A Paradoxical Ode' );
insert into relations values(4,F,'Magazine','Time','','','' );
insert into relations values(4,G,'Book','','','Clarissa','' );  
insert into relations values(4,H,'Publication','','','','Human Chemistry' );
insert into relations values(4,I,'Book','','','The Woman in White','' );
insert into relations values(5,K,'Book','','','Clarissa','' );  
insert into relations values(5,L,'Publication','','','','On the Nature of Things' );