Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
| Search | Today's Posts | Mark Forums Read
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
  #1 (permalink)  
Old November 22nd, 2003, 07:15 AM
Authorized User
 
Join Date: Jun 2003
Location: Shah Alam, Selangor, Malaysia.
Posts: 62
Thanks: 0
Thanked 0 Times in 0 Posts
Default Find Out First Item of each item Group

Hi,

I have a table as below:

item code
A01000
A01001
A0100A
A0100B
A0102B
A0102C
A0102D
B01041
B0104A
B0104C
.
.
.

from a table above, i want to list out a reault as this:


ITEM CODE
A01000
A0102B
B01041

I ONLY WANT TO LIST THE FIRST ITEM FOR THE ITEM IN THE SAME GROUPING OF THE FIRST 5 DIGITS.

HOW AM I WRITE A SQL TRANSACT AS ABOVE?


THANKS !


JANE
  #2 (permalink)  
Old November 22nd, 2003, 12:42 PM
planoie's Avatar
Friend of Wrox
Points: 16,481, Level: 55
Points: 16,481, Level: 55 Points: 16,481, Level: 55 Points: 16,481, Level: 55
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Aug 2003
Location: Clifton Park, New York, USA.
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Try something like this:

SELECT MAX(itemcode) FROM tablename
GROUP BY SUBSTRING(itemcode, 0, 5)

Your syntax may vary depending on your DB platform. The important part is that you need to group by the desired portion of the field using the appropriate sub string syntax.

Peter
------------------------------------------------------
Work smarter, not harder.


Similar Threads
Thread Thread Starter Forum Replies Last Post
Accessing previous item in current-group() in loop mikeymikey XSLT 1 January 4th, 2008 06:47 AM
Item Templates hbansal ASP.NET 1.0 and 1.1 Professional 6 August 2nd, 2007 06:24 AM
Get the first item of a List hpox ASP.NET 2.0 Basics 1 February 16th, 2007 06:04 PM
One item in Listbox venterjo General .NET 2 February 1st, 2005 05:45 AM
Want Combo Box first item if only 1 item markw707 Access 3 June 9th, 2004 04:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.