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
 General SQL Server Forums
 New to SQL Server Programming
 Distinct feild when there is Duplicate

Author  Topic 

a.ashabi
Posting Yak Master

117 Posts

Posted - 2009-09-10 : 14:52:44
Hi.I need to get the first record when there is a duplication on my product_name field.
for instance:

PRODUCT_ID PRODUCT_NAME
1111 Magazine Pack
1112 Magazine Pack
1144 Novels
...
the result should be:

1111 Magazine Pack
1144 Novels
...

I'we wrote this query:
SELECT MIN(product_name) AS keyword
FROM tbl_adword_keyword
GROUP BY product_name
HAVING (COUNT(product_name) > 0)
order by product_name

which is good but I need to have the PRODUCT_ID's also,but when I'added the Product_id field It didn't give me the result.
Plz help me.
Thanks in advanced





webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-10 : 14:55:15
SELECT MIN(product_id), product_name AS keyword
FROM tbl_adword_keyword
GROUP BY product_name
HAVING (COUNT(product_name) > 0)
order by product_name



No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

a.ashabi
Posting Yak Master

117 Posts

Posted - 2009-09-10 : 15:08:42
thanks :)
Go to Top of Page

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2009-09-10 : 15:13:37
welcome


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page
   

- Advertisement -