Search code examples
sqlsql-serverquery-tuning

SQL Query Theory Question


I have a large historical transaction table (15-20 million rows MANY columns) and a table with one row one column. The table with one row contains a date (last processing date) which will be used to pull the data in the trasaction table ('process_date').

Question: Should I inner join the 'process_date' table to the transaction table or the transaction table to the 'process_date' table?


Solution

  • This is how I would do it

    SELECT <<list only columns you need>> 
    FROM large_historical_transaction_table t
    WHERE EXISTS (SELECT 1 FROM OneRowTable o 
                  WHERE o.last_processing_date = t.process_date)