我有想一起捆绑成一个单一查询这些多个SQL查询,让我能避免我的应用程序发送多个请求到数据库(我希望收到所有这些数据在一个单次):如何将多个SQL查询合并为一个?
1) select pin, officeNum, isVeteran from table18 where pin = 123;
2) select streetAddress, apartmentAddress, cityAddress, stateAddress from table1 where case = (select case from table18 where pin = 123);
3) select unitAddress, cityAddress, streetAddress, apartmentAddress from table5 where pin = 123;
4) select unitAddress, cityAddress, streetAddress, apartmentAddress from table55 where seqNum = 0 and rfa = (select rfa from table18 where pin = 123);
5) select unitAddress, cityAddress, streetAddress, apartmentAddress from table103 where histCode = 0 and case = (select case from table18 where pin = 123);
6) select phone, email from table715 where histSeqNum in (select max(histSeqNum from table715))
and histCode in (select max(histCode) from table715)
and case = (select case from table18 where pin = 123);
这里是我的架构:
(请原谅糟糕的设计,它是从数据库中创建20年前,没有外键)
-Table18(引脚(PK)的情况下, officeNum,isVeteran)
-Table1(情况(PK),caseOfficer,的StreetAddress,apartmentAddress,cityAddress,stateAddress)
-Table5(销(PK),的StreetAddress,apartmentAddress,cityAddress,stateAddress)
-Table55(RFA(CompositeKey ),SEQNUM(CompositeKey),rfaAddress,的StreetAddress,apartmentAddress,cityAddress,stateAddress)
-Table103(情况(CompositeKey),histCode(CompositeKey))
-Table715(情况(CompositeKey),histSeqNum(CompositeKey) ,histCode(CompositeKey),电话,电子邮件)
你准确的问题是什么? – 2012-03-10 20:56:44
@juergend。这是一些其他问题...... – gdoron 2012-03-10 20:58:31
没有看到一个模式有点困难,但它看起来像我使用子查询来执行连接。如果您可以提供更多信息,则应该可以重写,而不必有人需要首先对您的模式进行逆向工程。 – 2012-03-10 20:58:49