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 > How to select first and last row data ?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 04-04-10, 21:30
bh_hensem bh_hensem is offline
Registered User
 
Join Date: Jun 2009
Posts: 18
How to select first and last row data ?

Hi..

Below is sample of my data:-
E1234
C1234
X1234
Z1234
S1234
B1234

Based on data, how could i selct first and last row of the data ?. The resuler must be:-
First row: E1234
Last row: B1234

I have tried used max and min query but it will be sort the data A-Z.

Please advise..

Thank you,
Baharin
Reply With Quote
  #2 (permalink)  
Old 04-04-10, 21:40
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,525
no can do, sorry
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 04-04-10, 22:14
Pat Phelan Pat Phelan is offline
Resident Curmudgeon
 
Join Date: Feb 2004
Location: In front of the computer
Posts: 12,606
What determines the order of the rows presented?

Since rows in a table have no inherant order, we can assume any order so just select the first two rows, the min and max values, the last two rows, or anything else that is convenient. If you want to put some specific order on the rows, then things are a little trickier, but no big deal.

-PatP
__________________
In theory, theory and practice are identical. In practice, theory and practice are unrelated.
Reply With Quote
  #4 (permalink)  
Old 04-05-10, 02:11
healdem healdem is offline
Jaded Developer
 
Join Date: Nov 2004
Location: out on a limb
Posts: 9,250
As Pat P says you need to establish what makes the earliest row and what makes the latest row. so whatever it is (and I'm expecting its going to be a another column... probably some for of date/time or batch + sequence ID)
__________________
I'd rather be riding my Versys or my Tiger 800 let alone the Norton
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