I have two tables I need to join. There are 34-thousand entries in table 1, 5-thousand entries in table 2. So - there are only 5-thousand records that need to be joined from table 2 to table 1.
I am exporting the data.
I need to preserve all 34-thousand records in my SQL statement - those with entries in table 2 and those without.
LEFT JOIN seems right to preserve all of the records - but executes so slowly it's rediculous (it takes like an hour or more)! If I use INNER JOIN it executes in about 12 seconds - very acceptable - but only returns records with entries in BOTH tables (5000 of them only).
Here is the statement I am using:
Expand|Select|Wrap|Line Numbers
- SELECT
- assignments.AssignID,
- assignments.Assignment,
- assignments.Reporter,
- assignments.Notes,
- assignments.AssignDatetime,
- assigncontents.Content AS 'content'
- FROM assignments
- LEFT JOIN assigncontents
- ON assignments.AssignID = assigncontents.AssignID;
I have read that indexing will help - but I don't know how to do that.
Is that something I can simply turn on in the administrator application - or is there a better way to write the statement to execute faster?