If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Oracle > Basic question

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-16-03, 16:18
nmcbride nmcbride is offline
Registered User
 
Join Date: Jan 2003
Location: Harpenden, England
Posts: 1
Unhappy Basic question

I have two fields in a table, customer and reference.
A problem has occured that means the same references have been assigned to different customers in errors.
Ignoring the fact that constraints could have prevented this, how would I identify the rows where more than one customer is attached to the same reference.

The current SQL I am using is:

select customer,reference
from table
where reference in
(select reference from
(select reference,count(*) from
table
group by reference
having count(*) > 1))

This appears to work but I suspect there is a simpler method - any ideas as this can take a long time?
Reply With Quote
  #2 (permalink)  
Old 01-16-03, 16:58
andrewst andrewst is offline
Moderator.
 
Join Date: Sep 2002
Location: UK
Posts: 5,171
Re: Basic question

You don't need so many subqueries:

select customer,reference
from table
where reference in
(select reference from table
group by reference
having count(*) > 1)

I don't think there is a quicker way than that, assuming there is an index on table.reference (if not add maybe one first).
__________________
Tony Andrews
http://tinyurl.com/tonyandrews
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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