Welcome to dbFreaks.com!
FAQFAQ    SearchSearch      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Help for a simple (?) query

 
   Database Help (Home) -> MSEQ RSS
Next:  RSgvs_GenVal2Str  
Author Message
Big Passeron

External


Since: Oct 10, 2008
Posts: 3



(Msg. 1) Posted: Fri Nov 28, 2008 6:43 am
Post subject: Help for a simple (?) query
Archived from groups: microsoft>public>sqlserver>mseq (more info?)

I'm stuck with a (I think) simple query.
A table (Extracted_Data) is made of a PK (id), a date value (Data_Time) and
a int (iddevice).
Another table (Device) holds a relationship with the previous table, by
means of its PK column id, while the other column (Device_Name) is
varchar(64).
I'd like to be able to find just the last data extracted by every device
(e.g. Device1's last value was taken on 07/12/08, Device2's on 11/10/08 and
so on)
This way, assuming that Extracted Data contains 30000 rows and Devices
contains 50 rows, I want the query to retrieve 50 distinct rows from 50
different devices.
Is it possible?

Thanks for your help

 >> Stay informed about: Help for a simple (?) query 
Back to top
Login to vote
Mohit K. Gupta

External


Since: Jun 13, 2008
Posts: 41



(Msg. 2) Posted: Fri Nov 28, 2008 9:29 am
Post subject: RE: Help for a simple (?) query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Tr7 ..

SELECT Device_Name,
Last_Used = ( SELECT TOP 1 LastUsedDate
FROM Extracted_Data AS ED
WHERE ED.IDDevice = D.ID
ORDER BY LastUsedDate DESC)
FROM Devices AS D

--
Mohit K. Gupta
B.Sc. CS, Minor Japanese
MCITP: Database Administrator
MCTS: SQL Server 2005
http://sqllearnings.blogspot.com/


"Big Passeron" wrote:

> I'm stuck with a (I think) simple query.
> A table (Extracted_Data) is made of a PK (id), a date value (Data_Time) and
> a int (iddevice).
> Another table (Device) holds a relationship with the previous table, by
> means of its PK column id, while the other column (Device_Name) is
> varchar(64).
> I'd like to be able to find just the last data extracted by every device
> (e.g. Device1's last value was taken on 07/12/08, Device2's on 11/10/08 and
> so on)
> This way, assuming that Extracted Data contains 30000 rows and Devices
> contains 50 rows, I want the query to retrieve 50 distinct rows from 50
> different devices.
> Is it possible?
>
> Thanks for your help

 >> Stay informed about: Help for a simple (?) query 
Back to top
Login to vote
Big Passeron

External


Since: Oct 10, 2008
Posts: 3



(Msg. 3) Posted: Fri Nov 28, 2008 10:51 am
Post subject: RE: Help for a simple (?) query [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Works great...
Thanks a lot Mohit!

"Mohit K. Gupta" wrote:

> Tr7 ..
>
> SELECT Device_Name,
> Last_Used = ( SELECT TOP 1 LastUsedDate
> FROM Extracted_Data AS ED
> WHERE ED.IDDevice = D.ID
> ORDER BY LastUsedDate DESC)
> FROM Devices AS D
>
> --
> Mohit K. Gupta
> B.Sc. CS, Minor Japanese
> MCITP: Database Administrator
> MCTS: SQL Server 2005
> http://sqllearnings.blogspot.com/
>
>
> "Big Passeron" wrote:
>
> > I'm stuck with a (I think) simple query.
> > A table (Extracted_Data) is made of a PK (id), a date value (Data_Time) and
> > a int (iddevice).
> > Another table (Device) holds a relationship with the previous table, by
> > means of its PK column id, while the other column (Device_Name) is
> > varchar(64).
> > I'd like to be able to find just the last data extracted by every device
> > (e.g. Device1's last value was taken on 07/12/08, Device2's on 11/10/08 and
> > so on)
> > This way, assuming that Extracted Data contains 30000 rows and Devices
> > contains 50 rows, I want the query to retrieve 50 distinct rows from 50
> > different devices.
> > Is it possible?
> >
> > Thanks for your help
 >> Stay informed about: Help for a simple (?) query 
Back to top
Login to vote
Display posts from previous:   
Related Topics:
Simple Query problem - Sample table as follows Order ID Stock Code Status --------- ------- ------- 203 STK1 3 203 STK2 2 203 STK4 3 204 STK1 3 204 STK5 3 205 ..

Running a Update query based on information from Insert Qu.. - I am trying to setup a script where I run an insert query to insert information into a table. The first part I have down pat as far as the Insert, where I'm having difficulties is that the information is coming from an outside source and the input..

Hopefully a basic query question - Good afternoon, I am trying to create a query. Underlying data in table is: Job No/Cost Type/$ J8000/1/3000 J8000/2/2000 J8000/2/5000 J8000/2/1000 In the above a Cost type of 1 equates to Labour cost, and a Cost type of 2 equates to Materials cost....

How have you replaced English Query? - Since Microsoft decided to not continue supporting English Query after SQL Server 2000 what have those of you how used it replaced it with?

query assistance -return most recent date - I have a table that has two fields, pkg_num, which is a number, and del_date_time, which is a date-time. The table can contain duplicate pkg_num values, as long as the del_date_time values are different for any given number. I need a query that will...
   Database Help (Home) -> MSEQ All times are: Pacific Time (US & Canada)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You can edit your posts in this forum
You can delete your posts in this forum
You can vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]