User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the MS SQL section within the Web Development category of DaniWeb, a massive community of 391,944 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,872 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our MS SQL advertiser:
Views: 487 | Replies: 3 | Solved
Reply
Join Date: Nov 2006
Location: Feltwell, UK
Posts: 31
Reputation: dmmckelv is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Select Previous Row Values

  #1  
34 Days Ago
Is there a keyword in SQL that would allow you to select a value from a field in the previous row? I am looking for something that would give me the speed field value for the row before:
SELECT min(Parsed.Time), [Parsed.Number]
FROM Parsed
GROUP BY [Parsed.Rev Number]
Last edited by dmmckelv : 34 Days Ago at 3:58 am. Reason: more specific
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Mar 2007
Posts: 18
Reputation: wujtehacjusz is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
wujtehacjusz's Avatar
wujtehacjusz wujtehacjusz is offline Offline
Newbie Poster

Re: Select Previous Row Values

  #2  
34 Days Ago
You can always use join two tables using row_number()...
Reply With Quote  
Join Date: Nov 2006
Location: Feltwell, UK
Posts: 31
Reputation: dmmckelv is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 0
dmmckelv dmmckelv is offline Offline
Light Poster

Re: Select Previous Row Values

  #3  
33 Days Ago
Originally Posted by wujtehacjusz View Post
You can always use join two tables using row_number()...


My rows are not numbered. Any other suggestions?

Thanks!
Reply With Quote  
Join Date: Apr 2008
Posts: 295
Reputation: tesuji is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 41
tesuji tesuji is offline Offline
Posting Whiz in Training

Re: Select Previous Row Values

  #4  
31 Days Ago
Hello dmmckelv,

When Edgar Frank Codd invited relational databases his primary idea was to found it on
logic algebra and set theory. The rows of relational tables (aka relations) are sets. Therefore, there aren't duplicate rows nor any particular order of rows. From this point of view, "I am looking for something that would give me the speed field value for the row before" is rather irrelevant.

However, to put any meaningful signification on it, your table must already have a column
which allows such an ordering, for example date, timestamp or auto-increment numbers.
If you don't have such special column (or set of columns) within a table, it is impossible to determine the predecessor of a specific row because the today predecessor could be the successor row tomorrow (e.g. due to inserting and deleting rows in the meantime).

To cut a long story short, what's that special column of your table to get particularly ordered rows? You may also post the creating statement of your table.

-----
tesu
Information is moving—you know, nightly news is one way, of course, but it's also moving through the blogosphere and through the Internets. I promise you I will listen to what has been said here, even though I wasn't here. Ann and I will carry out this equivocal message to the world. I'm the master of low expectations.
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb MS SQL Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the MS SQL Forum

All times are GMT -4. The time now is 8:46 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC