Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Select first rows from subselect
Message
From
05/10/2015 20:46:42
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
Replication
Title:
Select first rows from subselect
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01625508
Message ID:
01625508
Views:
77
Good night, please help me with the following: I need to bring the first row from a table that have a lot of records but filtering for a specific column that is in other table:
models:
code     name       idcompany
001       BLUE          10
002       RED            20
003       BLACK        10
004       WHITE        99

data:
date           hour        model        temperature       energy
01/01/15      17:55    001                 4.5                  1
01/01/15      18:00    002                 5.5                  1
01/01/15      18:05    003                 6.3                  1
01/01/15      19:01    001                 6.5                  1
01/01/15      19:05    004                 5.5                  1
01/01/15      19:10    001                 4.5                  1
01/01/15      19:15    001                 4.5                  1
01/01/15      19:20    002                 5.5                  1
01/01/15      19:25    003                 6.3                  1
01/01/15      19:30    001                 6.5                  1
01/01/15      19:35    004                 5.5                  1
01/01/15      19:40    001                 4.5                  1


this is what I need:

results:
filtered by idcompany=10
code     name     date             hour          temp    energy
001       BLUE    01/01/15      19:40          4.5         1
003       BLACK  01/01/15      19:25          6.3         1
I need to bring the last record in data for the idcompany=10. I need this without using cursor or temporary table, would be possible with just one query?

TIA.
John Harold Belalcázar Lozano
Associate Director Of Development
http://www.belvicto.co/
jhbelalc@gmail.com
Next
Reply
Map
View

Click here to load this message in the networking platform