Let me ask you something I've been thinking about for a while. Imagine that you have two tables with data:
MAIN TABLE (A)
| ID | Date | |:-----------|------------:| | 1 | 01-01-1990| | 2 | 01-01-1991| | 3 | 01-01-1992| | 4 | 01-01-2000| | 5 | 01-01-2001| | 6 | 01-01-2003| SECONDARY TABLE (B)
| ID | Date | TOTAL | |:-----------|------------:|--------:| | 1 | 01-01-1990| 1 | | 2 | 01-01-1991| 2 | | 3 | 01-01-1992| 1 | | 4 | 01-01-2000| 5 | | 5 | 01-01-2001| 8 | | 6 | 01-01-2003| 7 | and you want to select only ID with date greater than 31-12-1999 and get the following columns: ID, Date and Total. For that we have many options but my question would be which of the following would be better in terms of performance:
OPTION 1
With main as( select id, date from A where date > '31-12-1999' ) select main.id, main.date, B.total from main inner join B on main.id = b.id OPTION 1
With main as( select id, date from A where date > '31-12-1999' ), secondary as ( select id, total from B where date > '31-12-1999' ) select main.id, main.date, secondary.total from main inner join secondary on main.id = b.id Which of both queries would be better in terms of performance? Thanks in advance!
DATE FOR BOTH TABLES MEANS THE SAME