get latest by each client

Posted on 2011-02-12
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
Question by:VBdotnet2005
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

Accepted Solution

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

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:

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]


Author Comment

ID: 34881527
thank you so much

Featured Post

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
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 insert data into a SQL Server database table using the Import/Export option and Bulk Insert.

617 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