greatwhitepine
11-22-2008, 05:29 PM
I have two tables with the following fields...
user (240,000 rows)
usr_id INTEGER PRIMARY KEY
usr_nme TEXT
fight (130,000 rows)
fght_id INTEGER AUTO_INCREMENT PRIMARY KEY
fght_exp INTEGER
fght_opnt_id INTEGER (FOREIGN KEY ON usr_id)
What is the SQL to determine the user name and user id of each oponent where the last fight with that opponent was worth at least 20 exp?
This takes so long to execute that I have never seen the results (over 5 minutes)...
SELECT u.usr_id, u.usr_nme FROM fight f, user u WHERE f.fght_id IN ( SELECT max( t.fght_id ) FROM fight t GROUP BY t.fght_opnt_id ) AND f.fght_opnt_id = u.usr_id AND f.fght_exp >= 20;
The inner query runs in less than 1 second and returns 47,000 rows.
user (240,000 rows)
usr_id INTEGER PRIMARY KEY
usr_nme TEXT
fight (130,000 rows)
fght_id INTEGER AUTO_INCREMENT PRIMARY KEY
fght_exp INTEGER
fght_opnt_id INTEGER (FOREIGN KEY ON usr_id)
What is the SQL to determine the user name and user id of each oponent where the last fight with that opponent was worth at least 20 exp?
This takes so long to execute that I have never seen the results (over 5 minutes)...
SELECT u.usr_id, u.usr_nme FROM fight f, user u WHERE f.fght_id IN ( SELECT max( t.fght_id ) FROM fight t GROUP BY t.fght_opnt_id ) AND f.fght_opnt_id = u.usr_id AND f.fght_exp >= 20;
The inner query runs in less than 1 second and returns 47,000 rows.