Wrox Programmer Forums
| Search | Today's Posts | Mark Forums Read
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 March 31st, 2005, 12:13 PM
Registered User
 
Join Date: Mar 2005
Location: Trevose, PA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default Distinct SELECT DISTINCT question...

Okay... Here is my conundrum. I have a table of products. This table is a list of products with associated components listed under one specific system number:

Sysno | Item Number | Description | Rate
----------------------------------------
  1 | C123C | Laptop | 250
  1 | A987A | Lap. Memory |
  1 | A876A | Lap. Case |
  2 | C234C | Projector | 300
  2 | A765A | Proj. Case |
  2 | A654A | Proj. Bulb |
  3 | C345C | Technician | 50
  3 | A543A | Travel |

I realize that this is NOT an ideal product list, but I cannot modify it as it is the company's master database for a completely different complex piece of software.

I want to select all the data from each row (like SELECT *) BUT I only want the first of the distinct Sysno fields so my recordset would look like this:

Sysno | Item Number | Description | Rate
----------------------------------------
  1 | C123C | Laptop | 250
  2 | C234C | Projector | 300
  3 | C345C | Technician | 50

How can I accomplish this through a heavily modified Select statement?

Thank you all SO much in advance!

  #2 (permalink)  
Old March 31st, 2005, 03:16 PM
Friend of Wrox
 
Join Date: Jan 2004
Location: , , USA.
Posts: 303
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try this..not sure what databae are you using

SQL Server T-SQL Query

SELECT Sysno,Item_Number,[Description],Rate
From Table
Group By Sysno,Item_Number,[Description],Rate
Having Rate IS NOT NULL
  #3 (permalink)  
Old April 1st, 2005, 11:20 AM
Registered User
 
Join Date: Mar 2005
Location: Trevose, PA, USA.
Posts: 5
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hmmm, I guess I didn't specify too much.

My bad...

I am programming in VBscript, pulling data through ODBC from a FoxPro Database.

Also, I would really like to have the SQL statement select the distinct products via the Sysno. This way, I dont take a chance on their being additional rate data that would throw the statement off. I know for sure that the Sysno data will not change.

  #4 (permalink)  
Old April 6th, 2005, 10:23 AM
Authorized User
 
Join Date: Mar 2005
Location: , , .
Posts: 14
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Try using SELECT DISTINCT Sysno, Item Number, Description, Rate FROM TableName.

  #5 (permalink)  
Old August 18th, 2005, 08:53 AM
Registered User
 
Join Date: Jun 2005
Location: , , .
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Default


EndEffect,

Given that you are using ODBC with a Foxpro database, you could do the following:

SELECT * FROM MyTable GROUP BY Sysno

Note that this is not normally legal SQL syntax, but it works with the Foxpro ODBC driver because the driver is up to date only as of Visual FoxPro 6.0, and that version was very forgiving of this syntax. It should produce the result you want.

Mike




Similar Threads
Thread Thread Starter Forum Replies Last Post
Select Distinct Question DeMoNN SQL Server 2000 4 November 1st, 2006 02:52 PM
Select Distinct Question DeMoNN Access 4 November 1st, 2006 11:15 AM
Select Distinct Question acdsky SQL Server 2000 6 October 31st, 2006 05:16 PM
Select Distinct kirkmc Access 13 July 13th, 2006 01:26 PM
select distinct bmains ADO.NET 0 April 8th, 2004 02:50 PM





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