Hi,
Can anyone tell me how to select the "most recent" date values from a
grouped query? Consider the following:
CREATE TABLE [dbo].[TestQuery] ( [ID] [int] NOT NULL , [ID_Parent] [int] NOT
NULL , [Date] [datetime] NOT NULL ) ON [PRIMARY]
This is a simplified adjacency list. What I want to do is find the highest
valued item by date for each sub-tree. In other words, the single highest
date item when This.ID_Parent = That.ID_Parent. I think I first need to
group by ID_Parent, then select the TOP 1 from this query, but how to
aggregate them so I get the TOP 1 for each ID_Parent?
Thanks for any help you can give me,
Robin 3 1781
Another way:
SELECT T1.id_parent, MAX(T1.id) AS id, T1.date
FROM TestQuery AS T1
WHERE T1.date =
(SELECT MAX(date)
FROM TestQuery AS T2
WHERE T1.id_parent = T2.id_parent)
GROUP BY T1.id_parent, T1.date
--
David Portas
SQL Server MVP
--
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Try this:
SELECT T1.id_parent, MAX(T1.id) AS id, T1.date
FROM TestQuery AS T1
LEFT JOIN TestQuery AS T2
ON T1.id_parent = T2.id_parent
AND T1.date < T2.date
WHERE T2.date IS NULL
GROUP BY T1.id_parent, T1.date
--
David Portas
SQL Server MVP
--
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
here is a related article:
subject: select first record from a group ordered by 3 columns
date: Nov 27 2002, 5:01 am http://groups-beta.google.com/group/...3b16be2b945c0f
David Portas wrote: Another way:
SELECT T1.id_parent, MAX(T1.id) AS id, T1.date FROM TestQuery AS T1 WHERE T1.date = (SELECT MAX(date) FROM TestQuery AS T2 WHERE T1.id_parent = T2.id_parent) GROUP BY T1.id_parent, T1.date
-- David Portas SQL Server MVP --
*** Sent via Developersdex http://www.developersdex.com *** Don't just participate in USENET...get rewarded for it! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: ian justice |
last post by:
Before i post actual code, as i need a speedyish reply.
Can i first ask if anyone knows off the top of their head, if there is
a likely obvious cause to the following problem.
For the moment i've reduced my form request to a simple text string
entry, instead of my desired optional parameters. As i have been stuck
with a single unfathomable glitch for over a year.
Basically, if i enter queries such as ;
"select * from table" "select * from...
|
by: Luca T. |
last post by:
Hello,
i need a way to find the home folder of the current user no matter if i am
in Linux or Windows for instance:
* Linux: /home/username
* Windows: C:\Documents and Settings\username
Is there any general way to do this?
|
by: strutsng |
last post by:
<input type="file"> only allows the user to browse for files.
How about "browse for folder" dialog? Can html/javascript do that? I
couldn't find any syntax for that. If not, please advise what are the
other approaches.
please advise. thanks!!
|
by: Greg Bell |
last post by:
Hi,
Can someone tell me where to look to enable me to read "Folder Options" user
settings for hidden/system files from within C#/VB.Net/Any other .NET
language. I'm pretty sure it must be part of the framework, but I'm buggered
if I can figure out which part. I've tried googling for it, but to no avail.
Any ideas?
Thanks
|
by: DC Gringo |
last post by:
I am having a bear of a time with setting a URL query string as a text value
in a dropdownlist and Server.URLEncode does not seem to do its job.
theFullLink = theLinkPrefix & theImageryTypeTrimmed &
Server.URLEncode("&f=")
ddlMyDropDownList.Items.Add(New ListItem("MyTextValue", theFullLink & "af"))
Which puts out the following HTML:
<option value="~/folder/page.aspx?param1=value1%26f%3daf">-
| |
by: Benny Ng |
last post by:
Dear All,
Now I just finished my winform application. And a part of that is to
send email reminder to the users. It's working fine in the server that with
SMTP service in Windows 2003.
But now the user wants to used the Linux server to send email messages.
(already installed the SMTP service in that). Unfortunatelly one error shown
after the sending funciton invoked.
It shows "Pickup directory is not existed,x,x,x,,"
|
by: =?Utf-8?B?S2Fyc3RlbiBMdW5kc2dhYXJk?= |
last post by:
Hi, I have made an application in C#, where I use the statement
Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles)
to get the name of the "Program Files" folder.
It works fine in "Windows 2000" and "Windows XP", but it fails when I'm
using "Windows Vista Ultima" in Danish. It returns "Program Files" instead of
"Programmer".
"Programmer " is the name of the folder in explore.
Hope someone can help me - Thanks
|
by: Keith G Hicks |
last post by:
I'm having a lot of trouble with "file in use" errors in my "folder watcher"
project. Starting and stopping the watcher and reading my XML file work
fine. Once the watcher is started, I'm reading the text files from the
watched folder line by line into variables and then posting them to a SQL
table.
All of the code for the form is shown below. And it works fine except for 2
issues.
First issue: In the Finally of the Try for teh SQL...
|
by: Simon van Beek |
last post by:
Dear reader,
Under | Tools | Options | the form Options will open.
Under the tab you find the field "Default database folder".
By opening the form this field shows on my pc I:\.
I can't close the form because then the message pups up
"MS Office Access can't change the work directory to I:\ "
If I change it to D:\ I can close the form but by opening the form
again the field is still showing I:\.
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |