JOINing two tables with 2 SELECT Statements

  • I am joining 2 tables of 30 columns with 5 mil and 50 columns with 10 mil rows. Now, I only need 5 columns from the 5 mil table and 15 columns from the 10 mil table. What is the best way to join these two tables to gain the best performance? I simplified a real issue I am facing with the above question. I can do the following:

    do a inner join of the two tables by name and return the 20 columns from the SELECT list. I need to return all rows.

    do a inner join of two SELECT statements made for each tables returning only the needed columns.

    I am getting mixed results, and therefore want to take a poll from the Pros here...Thanks a lot for helping.

  • Don't try to write anything over-complicated. The KISS principal applies here.

    Keep the join condition separate from any other filters, which should be written as where conditions.

    Try to use only SARG-able predicates in where and join conditions which you are trying to support with indexes.

    Make sure you have indexes which will support the query, but only provided they won't cause as much or more pain on other operations than they save on this one.

    Don't have any query hints/table hints or anything like that unless you can prove that it's useful.

    Tom

  • Great advice. Thanks Tom.

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply