943,568 Members | Top Members by Rank

Ad:
  • MS SQL Discussion Thread
  • Marked Solved
  • Views: 4144
  • MS SQL RSS
Jul 18th, 2008
0

Select Previous Row Values

Expand Post »
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:
MS SQL Syntax (Toggle Plain Text)
  1. SELECT min(Parsed.Time), [Parsed.Number]
  2. FROM Parsed
  3. GROUP BY [Parsed.Rev Number]
Last edited by dmmckelv; Jul 18th, 2008 at 4:58 am. Reason: more specific
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Jul 18th, 2008
0

Re: Select Previous Row Values

You can always use join two tables using row_number()...
Reputation Points: 12
Solved Threads: 7
Newbie Poster
wujtehacjusz is offline Offline
18 posts
since Mar 2007
Jul 18th, 2008
0

Re: Select Previous Row Values

You can always use join two tables using row_number()...
My rows are not numbered. Any other suggestions?

Thanks!
Reputation Points: 10
Solved Threads: 0
Light Poster
dmmckelv is offline Offline
33 posts
since Nov 2006
Jul 20th, 2008
1

Re: Select Previous Row Values

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
Reputation Points: 158
Solved Threads: 98
Master Poster
tesuji is offline Offline
720 posts
since Apr 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MS SQL Forum Timeline: Urgent Help needed.....
Next Thread in MS SQL Forum Timeline: [Help] Procedure





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC