Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 21
Default SQL - list items that have duplicates

I can't seem to figure out how to list items that have duplicates. I can
list items and their related counts, but can't just list the items with
duplicates.

This SQL statement lists items and their counts
SELECT VENDID, COUNT(*) AS VENDIDCOUNT FROM VENDTABLE GROUP BY VENDID

but this one doesn't seem to work
SELECT VENDID FROM VENDTABLE WHERE VENDIDCOUNT 1 IN (SELECT COUNT(*) AS
VENDIDCOUNT FROM VENDTABLE GROUP BY VENDID)

Thanks for the help!
Dave

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,298
Default SQL - list items that have duplicates

you need a HAVING statement eg
here's an example

SELECT VENDID, COUNT(*) AS VENDIDCOUNT FROM
(
select * from

(select 'A'[VENDID]
union all
select 'B'
union all
select 'C'
union all
select 'B'
) [VENDTABLE]
)[x]
group by VENDID
having count(vendid)1

Patrick Molloy
Microsoft Excel MVP

"dave k" wrote:

I can't seem to figure out how to list items that have duplicates. I can
list items and their related counts, but can't just list the items with
duplicates.

This SQL statement lists items and their counts
SELECT VENDID, COUNT(*) AS VENDIDCOUNT FROM VENDTABLE GROUP BY VENDID

but this one doesn't seem to work
SELECT VENDID FROM VENDTABLE WHERE VENDIDCOUNT 1 IN (SELECT COUNT(*) AS
VENDIDCOUNT FROM VENDTABLE GROUP BY VENDID)

Thanks for the help!
Dave

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Condensing a list with duplicates to a list with non-duplicates Nuclear Excel Worksheet Functions 2 July 29th 08 08:03 PM
SUMPRODUCT to count items with duplicates where another column contains two defined items PCLIVE Excel Worksheet Functions 4 September 8th 07 10:33 AM
Remove Duplicates; How can I get a list of items removed? Kjenkins Excel Discussion (Misc queries) 2 June 19th 07 10:57 PM
named range, data validation: list non-selected items, and new added items KR Excel Discussion (Misc queries) 1 June 24th 05 05:21 AM
Transfer Items to a list with no duplicates [email protected] Excel Worksheet Functions 1 March 30th 05 10:30 PM


All times are GMT +1. The time now is 04:18 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"