If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > WinSQL Lite - Retrieving top N rows

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 10-06-10, 02:28
m_spogter m_spogter is offline
Registered User
 
Join Date: Oct 2010
Posts: 2
WinSQL Lite - Retrieving top N rows

Hi,

I'm a novice user and cannot retrieve the first 5 or 10 rows from a database table. Please help. I'm using WinSql.

Last edited by m_spogter; 10-06-10 at 02:56. Reason: Poor spelling
Reply With Quote
  #2 (permalink)  
Old 10-06-10, 04:30
healdem healdem is online now
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
so create your query
set an appropriate ORDER BY clause
and use LIMIT X where X is the number of rows to reutrn

so thats
SELECT my,column,list FROM mytable
WHERE acondition evaluates as true /*such as ColumnA < 9.37 */
ORDER BY a,column,list
LIMIT 5

MySQL :: MySQL 5.1 Reference Manual :: 12.2.8 SELECT Syntax

bear in mind that databases have no concept of the first or last or whatever records unless you specify an order. the data is stuffed into a table and will be retrieved depending on some criteria the db decides (that may be the primary key, that may be the last index used, it may be the phase of the moon)
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
Reply With Quote
  #3 (permalink)  
Old 10-06-10, 04:43
m_spogter m_spogter is offline
Registered User
 
Join Date: Oct 2010
Posts: 2
Thanks

THanks, it worked!!!
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On