Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
Register
Register | FAQ | Members List | Calendar | 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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #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
Reply With Quote
  #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.
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 10:03 AM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.