Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
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 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
 
Old June 21st, 2011, 04:08 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default matching attributes in two columns

Hello,

I need help constructing an SQL query to find matching data in a table across two columns (Oracle 11g, but this is so basic I suspect the exact brand of SQL doesn't matter).

I have a large table with a PK of 'ModuleItemID', a 'ModuleNumber' column matching to a lookup table, and a 'PartNo' column. A single ModuleNumber can be associated with many PartNo's, but each PartNo should only appear with each ModuleNumber once.

I need to root out several instances of the above - "find all ModuleItemID rows with a particular ModuleNumber and PartNo where count >1" - but I'm not sure what the exact syntax is.

In the example below, I want to find duplicate rows like 1 & 3 and 7 & 9:


<code>
ModuleItemID ModuleNumber PartNo
1 1 161-4514
2 1 168-0056
3 1 161-4514
4 2 160-4514
5 2 168-0056
6 3 160-4514
7 3 171-0023
8 3 181-0565
9 3 171-0023
</code>


Thanks for any advice!

Last edited by Nostromo77; June 21st, 2011 at 04:20 PM.. Reason: edited to fix tabular data
 
Old June 22nd, 2011, 12:03 PM
Authorized User
 
Join Date: Oct 2006
Posts: 42
Thanks: 3
Thanked 0 Times in 0 Posts
Default All set...

I seem to have found a solution; the following Query did the trick:

Code:
SELECT MODULE_CD, COUNT(MODULE_CD), PART_NO, COUNT(PART_NO)
FROM MYTABLE
GROUP BY MODULE_CD, PART_NO
HAVING (COUNT(MODULE_CD) > 1) AND (COUNT(PART_NO) > 1)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Matching Whitespace iceandrews XSLT 3 October 27th, 2010 12:49 PM
Value matching with Range values manojkumarsoni Excel VBA 2 April 6th, 2010 08:53 AM
Display HTML Attributes from XML Attributes rangeshram XSLT 3 March 27th, 2010 01:14 PM
Matching two strings jamie_t VB How-To 0 October 12th, 2005 03:40 AM
Finding a matching value Morry Excel VBA 2 March 26th, 2004 05:32 AM





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