Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

get latest by each client

Posted on 2011-02-12
2
Medium Priority
?
310 Views
Last Modified: 2012-05-11
I want to get the latest grouping by idx of each bank.
result like this
2011-02-11 11:08:32.700 BOFA   BANK OF AMERICA
2011-01-11 11:09:32.700 CHS     CHASE BANK
2011-02-12 11:09:32.700 AMC     AMERICAN HOME

Here is a sample table





MODIFIED DATE                IDX       BANK_NAME
2011-02-10 11:07:32.700 BOFA   BANK OF AMERICA
2011-02-11 11:08:32.700 BOFA   BANK OF AMERICA
2011-01-10 11:09:32.700 AMC     AMERICAN HOME
2011-01-10 11:09:32.700 CHS     CHASE BANK
2011-01-10 11:09:32.700 AMC     AMERICAN HOME
2011-02-11 11:09:32.700 BOFA   BANK OF AMERICA
2011-01-11 11:09:32.700 CHS     CHASE BANK
2011-02-12 11:09:32.700 AMC     AMERICAN HOME
0
Comment
Question by:VBdotnet2005
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 9

Accepted Solution

by:
ezraa earned 2000 total points
ID: 34881510
You can select the max(date) and group by the IDX and BANK_NAME field:

select max([MODIFIED DATE]), IDX,  BANK_NAME
from MyTable
group by IDX,  BANK_NAME;


If you can have different BANK_NAMEs for a IDX you may need a query similar to this one to achive the output you're looking for:

select t.[MODIFIED DATE], t.IDX,  t.BANK_NAME
from (
   select IDX, max([MODIFIED DATE]) as [MODIFIED DATE]
   from myTable group by IDX
) as m inner join MyTable t on m.IDX = t.IDX and m.[MODIFIED DATE] = t.[MODIFIED DATE]

0
 

Author Comment

by:VBdotnet2005
ID: 34881527
thank you so much
0

Featured Post

Moving data to the cloud? Find out if you’re ready

Before moving to the cloud, it is important to carefully define your db needs, plan for the migration & understand prod. environment. This wp explains how to define what you need from a cloud provider, plan for the migration & what putting a cloud solution into practice entails.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever wondered why sometimes your SQL Server is slow or unresponsive with connections spiking up but by the time you go in, all is well? The following article will show you how to install and configure a SQL job that will send you email alerts includ…
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties

718 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question