Total SQL Newbie here!
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:
[code=mysql]
SELECT
assignments.Ass ignID,
assignments.Ass ignment,
assignments.Rep orter,
assignments.Not es,
assignments.Ass ignDatetime,
assigncontents. Content AS 'content'
FROM assignments
LEFT JOIN assigncontents
ON assignments.Ass ignID = assigncontents. AssignID;
[/code]
I am using MySQL 5.0.
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?
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:
[code=mysql]
SELECT
assignments.Ass ignID,
assignments.Ass ignment,
assignments.Rep orter,
assignments.Not es,
assignments.Ass ignDatetime,
assigncontents. Content AS 'content'
FROM assignments
LEFT JOIN assigncontents
ON assignments.Ass ignID = assigncontents. AssignID;
[/code]
I am using MySQL 5.0.
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?
Comment