Soldato
- Joined
- 22 Aug 2005
- Posts
- 8,968
- Location
- Clydebank
Hi all
Wonder if anyone knows how I can get around this problem:
2 DB tables:
main_table_2:
id, app_no, date,
csv_table:
id, app_no, book_date, pub_date
(book_date should match date, and app_no should match app_no)
What I'm doing is importing a CSV into the CSV table and then comparing against the main_table_2 and trying to produce a table that shows me records in the csv_table that AREN'T in the main_table_2.
This is my query:
But it takes 26 seconds to compute.
Explain SQL
Can anyone tell me what's wrong or improve on the query?
Cheers
Wonder if anyone knows how I can get around this problem:
2 DB tables:
main_table_2:
id, app_no, date,
csv_table:
id, app_no, book_date, pub_date
(book_date should match date, and app_no should match app_no)
What I'm doing is importing a CSV into the CSV table and then comparing against the main_table_2 and trying to produce a table that shows me records in the csv_table that AREN'T in the main_table_2.
This is my query:
Code:
SELECT `csv_table`.`app_no` AS `CSV_app`,
`pub_date`, `book_date`
FROM `csv_table`
LEFT JOIN `main_table_2`
ON `main_table_2`.`app_no` = `csv_table`.`app_no`
WHERE `book_date` = '2009-06-05'
AND `main_table_2`.`app_no` is NULL
But it takes 26 seconds to compute.
Explain SQL
Code:
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE csv_table ALL NULL NULL NULL NULL 242 Using where
1 SIMPLE main_table_2 index NULL app_no 47 NULL 227210 Using where; Using index; Not exists
Can anyone tell me what's wrong or improve on the query?
Cheers