Microsoft
Software
Hardware
Network
Question : SQL query for values less than a sequential number but depending on other column value
I have data similar to this
ID Value Seq
1 A 1
1 B 2
1 C 3
1 D 4
1 E 5
2 A 1
2 B 2
2 D 3
2 C 4
2 E 5
I need to query the values for all rows where the Value is less than the Seq for the row that contains a "D".
The result set would be:
ID Value Seq
1 A 1
1 B 2
1 C 3
2 A 1
2 B 2
Thanks!
Answer : SQL query for values less than a sequential number but depending on other column value
SELECT t1.ID, t1.Value, t1.Seq
FROM SomeTable t1 INNER JOIN
(SELECT t2.ID, t2.Seq
FROM SomeTable t2
WHERE t2.Value = 'D') x ON t1.ID = x.ID AND t1.Seq < x.Seq
ORDER BY t1.ID, t1.Value, t1.Seq
Random Solutions
Cannot Create a Fax Account in Windows 7
Trimming the beginning and end of a string
Block Logme internally
Doing an INSERT or Update based on if the record already exists or not while importing data from a text file to SQL SERVER 2005.
Difference between Icefaces,myfaces,richfaces
in JSF?
permissions to be able to script objects
Change primary smtp addresses for 29 users using powershell for exchange
New Windows 7 workstations in existing SBS 2003 domain
HP z200 Workstation Windows 2008 R2 'PCI serial port' driver and 'PCI Simple Communications controller' driver needed
64-bit version of Acrobat PDF Add-in for Office 2010?