Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Stumper SQL Query?

Author  Topic 

cj77
Starting Member

1 Post

Posted - 2002-08-17 : 11:20:28
I have written the following select statement:

SELECT NOTES_IMAGES.LIN1, PRODUCT_INFO.Id AS ProdId
FROM PRODUCT_INFO INNER JOIN
NOTES_IMAGES ON
PRODUCT_INFO.NBR = NOTES_IMAGES.KEY_FLD INNER JOIN
CORP_GIFTS ON
PRODUCT_INFO.NBR = CORP_GIFTS.ProductNumber
WHERE (PRODUCT_INFO.ECOMMERCE_FLG = N'Y') AND
(PRODUCT_INFO.REG_PRC > 1)
GROUP BY PRODUCT_INFO.Id, NOTES_IMAGES.LIN1

It returns results like this:

LIN1 PRODID
image1.jpg 13523
image1.jpg 13524
image1.jpg 12633
image2.jpg 23553
image2.jpg 85334

What I really want is to return a list of DISTINCT image names (LIN1) and the first product number associated with that. For example, this is what I want to get from the database:

LIN1 PRODID
image1.jpg 13523
image2.jpg 23553

I'm TOTALLY stumped. Any and all help would be most appreciated. Thanks (a newbie SQL Query writer)

r937
Posting Yak Master

112 Posts

Posted - 2002-08-17 : 13:30:38
SELECT NOTES_IMAGES.LIN1
, min(PRODUCT_INFO.Id) AS FirstProdId
FROM ...
WHERE ...
GROUP BY NOTES_IMAGES.LIN1

assuming "first" means "lowest id"


rudy
http://rudy.ca/

Go to Top of Page
   

- Advertisement -