开发者

SQL Server OUTER JOIN multiple linked fields

I am trying to query data from two tables into one tables using OUTER JOIN.开发者_高级运维 The thing is that to uniquely identify the rows, three fields are needed. This brings me to query containing this expression:

FROM Data1 DB
  RIGHT OUTER JOIN Data2 FT on (DB.field1 = FT.Value1 
                                and DB.field2 = FT.field2 
                                and DB.field3 = FT.field3)

However, the query runs for pretty much forever. To test the whole thing I used WHERE conditions and FULL OUTER JOIN and in the case of WHERE conditions it is done almost instantly whereas using the FULL OUTER JOIN I had the same trouble and usually ended up cancelling the whole thing after 5 minutes or so.

Can anyone see what I am doing wrong with my query? Thanks for any help!


Do you really need all the records back from the query? Some WHERE criteria could cut execution time down considerably.

Yes, and indexes. Check the plan and create recomended indexes.


Your best bet is to view the execution plan (and if you are comfortable with it, post a screenshot of it in your question). That'll tell you where the most expensive portion of the query is happening.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜