|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Trying to select last record...
I have a sql query that looks for values in a few different databases....
is there a way to select the last record in the table b/c I am pulling the hours worked on jobs and one person may have 3 job titles but i want it to show the balance of hours under the most recent job... Instead all the jobs are showing the same value even though only one of them had those hours under it. I think a way to get around this is to select the last value b/c that is under the job title most recently worked and they are in order by timesheets which can be ordered by date...any ideas? |
|
#2
|
|||
|
|||
|
a fundamental concept that I missed too...you have to understand that in relational db's there is no "first" or "last" record, just b/c you see it that way in the result set grid doesn't mean that's how it is in the database. You have to have some value or condition to view or pull a record. If you post some sample data from the table and what you want to happen, then we can probably get you rolling.
|
|
#3
|
|||
|
|||
|
To continue with where NULL was going: If you have an autoincrement ID field in the table, you'd do this to pull the last record:
Code:
SELECT TOP 1 * FROM tableName ORDER BY ID DESC |
![]() |
| Viewing: Dev Shed Forums > Databases > MS SQL Development > Trying to select last record... |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|