Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 467
Keng Avatar asked Dec 13 '22 21:12

Keng


2 Answers

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)
like image 76
SQLMenace Avatar answered Dec 24 '22 10:12

SQLMenace


An Inner join is a symmetrical, bi-directional relationship, in general it doesn't matter, but in this case I would suggest not joining at all, read the threshold date into a variable and pass it to the other select query as a parameter...

like image 21
Charles Bretana Avatar answered Dec 24 '22 10:12

Charles Bretana