dreamwest Posted January 26, 2009 Share Posted January 26, 2009 I need to limit and order this join by id (primary key) to 40 queries is there a way i can do this?? Is this even possible?? $query = "SELECT gallery_import.*, video.* ". "FROM gallery_import, video ". "WHERE gallery_import.description_import = video.title ORDER BY `video`.`id` DESC LIMIT 40"; $result = mysql_query($query) or die(mysql_error()); Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/ Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 There's no JOIN here (well ok... there is... sorta hidden ). It's a query, and you can limit it to 40 rows. And yes, it is possible, and this sntax should work. Do you get any errors? Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746388 Share on other sites More sharing options...
dreamwest Posted January 26, 2009 Author Share Posted January 26, 2009 no errors....its just buggy keeps overwriting values i dont want it to , maybe its how the query is structured.....but your right the limit works The reason i have to modify it is because it taking over 7 minuets to execute, and my site is database driven so i cant acess the site while the scripts running, and i need to run this every 20mins Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746395 Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 Do you have indexes created on 'gallery_import.description_import' and 'video.title' ? Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746400 Share on other sites More sharing options...
dreamwest Posted January 26, 2009 Author Share Posted January 26, 2009 no just the primary key is has an index. Ive never tried to index tables before, but i read if your alway updating values you can have a negative effect using indexes Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746405 Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 Wrong. You should always create indexes on fields you use to join tables. Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746407 Share on other sites More sharing options...
dreamwest Posted January 26, 2009 Author Share Posted January 26, 2009 Ok trying it now. I was able to bring the query time down to 40 seconds with the LIMIT , ill let you know how much the INDEX will bring it down by.... Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746410 Share on other sites More sharing options...
dreamwest Posted January 26, 2009 Author Share Posted January 26, 2009 Bit stuck with the INDEX creation, heres what ive got mysql_query("CREATE INDEX description_index ON gallery_import(description_import)") or die(mysql_error()); but im getting this error: BLOB/TEXT column 'description_import' used in key specification without a key length gallery_import is the table name Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746420 Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 Oh my... joining on BLOB fields... no wonder it is slow... CREATE INDEX description_index ON gallery_import(description_import(indexLength)) Instead of indexLength put number of characters you want to have indexed. Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746423 Share on other sites More sharing options...
dreamwest Posted January 26, 2009 Author Share Posted January 26, 2009 Brilliant!! Execution time = "Query took 0.0011 sec" Bit better than 7 minuets originally , site also runs faster Thanks Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746430 Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 Here's some lecture for you http://dev.mysql.com/doc/refman/5.1/en/mysql-indexes.html Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746431 Share on other sites More sharing options...
corbin Posted January 26, 2009 Share Posted January 26, 2009 Is: SELECT blah FROM sometable1 a JOIN sometable2 b ON b.some_column = a.some_col; faster than: SELECT blah FROM sometable1 a, sometable2 b WHERE b.some_column = a.some_col; or did I dream that? Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746975 Share on other sites More sharing options...
Mchl Posted January 26, 2009 Share Posted January 26, 2009 I can not point you to a source, but I read that MySQL query optimizer rewrites such joins to WHERE. So they're equivalent. Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-746982 Share on other sites More sharing options...
corbin Posted January 26, 2009 Share Posted January 26, 2009 Hrmmm yeah, I guess logically it probably handles them the same way. Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-747011 Share on other sites More sharing options...
fenway Posted January 27, 2009 Share Posted January 27, 2009 I can not point you to a source, but I read that MySQL query optimizer rewrites such joins to WHERE. So they're equivalent. Yes, but NEVER use comma. Quote Link to comment https://forums.phpfreaks.com/topic/142452-limit-join/#findComment-747557 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.