SELECT TOP
What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
Yeah, put LIMIT 20 on the end. - Original Message - From: Jim McAtee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 14, 2003 11:12 PM Subject: SELECT TOP What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
SELECT h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC limit 20; ^ You probably mean LIMIT to limit. On Mon, 2003-07-14 at 17:12, Jim McAtee wrote: What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- Woody In a world without boundaries why do we need Gates and Windows? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
Be careful! Phil wanted the top 20 and the limit 20 will only return a random 20 records. Regards, Jake Johnson [EMAIL PROTECTED] __ Plutoid - http://www.plutoid.com - Shop Plutoid for the best prices on Rims, Car Audio, and Performance Parts. On Mon, 14 Jul 2003, Phil Bitis wrote: Yeah, put LIMIT 20 on the end. - Original Message - From: Jim McAtee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 14, 2003 11:12 PM Subject: SELECT TOP What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
On Mon, 2003-07-14 at 17:44, Jake Johnson wrote: Be careful! Phil wanted the top 20 and the limit 20 will only return a random 20 records. Actually, LIMIT x will return the first x rows of a query, not random records. In fact, you can even combine ORDER BY and LIMIT if you want to get the first x rows of some order. http://www.mysql.com/doc/en/SELECT.html http://www.mysql.com/doc/en/LIMIT_optimisation.html gabe. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim remove TOP 20 from front, add 'limit 20' to back. William R. Mussatto, Senior Systems Engineer Ph. 909-920-9154 ext. 27 FAX. 909-608-7061 -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
Sure Woody and Phil are right; just take out TOP 20 and put LIMIT 20 at the end of your SQL. If you care for the docs, the page is at http://www.mysql.com/doc/en/SELECT.html Peter Eternal Designs Phil Bitis wrote: Yeah, put LIMIT 20 on the end. - Original Message - From: Jim McAtee [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Monday, July 14, 2003 11:12 PM Subject: SELECT TOP What's wrong with the following query? The application used to use Access via ODBC, now running MySQL 3.23.xx, MyISAM table, accessed via MyODBC 3.51.01. // Return last 20 searches SELECT TOP 20 h.historyid, h.searchstring, h.serverid, s.shortname FROM history h INNER JOIN servers s ON h.serverid = s.serverid WHERE h.employeeid = 9 ORDER BY h.historyid DESC Works fine once I remove the TOP 20 from the query. If this isn't supported, is there an equivalent? Thanks, Jim -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
No kidding. I didn't know that. Thanks a lot! Regards, Jake Johnson [EMAIL PROTECTED] __ Plutoid - http://www.plutoid.com - Shop Plutoid for the best prices on Rims, Car Audio, and Performance Parts. On Mon, 14 Jul 2003, Gabriel Guzman wrote: On Mon, 2003-07-14 at 17:44, Jake Johnson wrote: Be careful! Phil wanted the top 20 and the limit 20 will only return a random 20 records. Actually, LIMIT x will return the first x rows of a query, not random records. In fact, you can even combine ORDER BY and LIMIT if you want to get the first x rows of some order. http://www.mysql.com/doc/en/SELECT.html http://www.mysql.com/doc/en/LIMIT_optimisation.html gabe. -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: SELECT TOP
Jake Johnson wrote: No kidding. I didn't know that. Thanks a lot! Regards, Jake Johnson [EMAIL PROTECTED] __ Plutoid - http://www.plutoid.com - Shop Plutoid for the best prices on Rims, Car Audio, and Performance Parts. On Mon, 14 Jul 2003, Gabriel Guzman wrote: On Mon, 2003-07-14 at 17:44, Jake Johnson wrote: Be careful! Phil wanted the top 20 and the limit 20 will only return a random 20 records. Actually, LIMIT x will return the first x rows of a query, not random records. In fact, you can even combine ORDER BY and LIMIT if you want to get the first x rows of some order. http://www.mysql.com/doc/en/SELECT.html http://www.mysql.com/doc/en/LIMIT_optimisation.html gabe. You can even specify an offset like this LIMIT 10, 20. This will skip the top 10 and give you the next 20. -- Peter K. Aganyo Eternal Designs Inc., +1(617)344-8023 (fax voicemail)
SELECT TOP?
Hi all- I am really new to the list and mysql. Here is my Question. I am used to writing SELECT TOP [num] FROM [table] I have searched the documentation online and found no mention of how to do this. But I did find info on LIMIT that limits the number of records returned. Is this how mysql limits rows returned? I know it sounds like an easy question but I am curious. Thanks -Anthony
Re: SELECT TOP?
On Fri, 11 May 2001, Anthony Colli wrote: Hi all- I am really new to the list and mysql. Here is my Question. I am used to writing SELECT TOP [num] FROM [table] I have searched the documentation online and found no mention of how to do this. But I did find info on LIMIT that limits the number of records returned. Is this how mysql limits rows returned? I know it sounds like an easy question but I am curious. Thanks -Anthony yes. t. - Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail [EMAIL PROTECTED] To unsubscribe, e-mail [EMAIL PROTECTED] Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php