Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Speed Up In Statement 2

Status
Not open for further replies.

perrymans

IS-IT--Management
Nov 27, 2001
1,340
US
I am using the following pass-through (Access as a front-end) to find duplicate member numbers and then return all the records that have the duplicate member numbers:

Code:
SELECT * FROM Tbl_Members WHERE (Tbl_Members.MemberNr) In
(select MemberNr from Tbl_Members
group by MemberNr HAVING count(MemberNr)>1)
order by MemberNr desc;

It is ridiculously slow, which means I am not doing it right, probably.

Please let me know how I can speed this up.

Thanks. Sean.
 
Try

SELECT * FROM Tbl_Members a
inner join
(select MemberNr from Tbl_Members
group by MemberNr HAVING count(MemberNr)>1) b
on a.MemberNr = b.MemberNr

Ian

 
That seems unnecessarily complicated. How about:
[tt]
select * from Tbl_Members
group by MemberNr HAVING count(MemberNr)>1
order by MemberNr desc;
[/tt]
Or am I missing something?
 
the problem with that, tony, is that it doesn't return all the rows that have the duplicate member numbers

here's a sample table:
Code:
CREATE TABLE Tbl_Members
( MemberNr INTEGER 
, Name VARCHAR(99)
);
INSERT INTO Tbl_Members VALUES
 ( 1001, 'Tom' )
,( 1002, 'Dick' )
,( 1001, 'TomAgain' )
,( 1003, 'Harry' )
here's the correct result produced by perryman's query:
Code:
MemberNr Name
1001     Tom
1001     TomAgain
here's the incorrect result produced by your query:
Code:
MemberNr Name
1001     Tom

r937.com | rudy.ca
 
rule of thumb: any time you use GROUP BY along with the dreaded, evil "select star" you almost surely are not going to get what you think you're going to get

besides, you can't even do it in any other database system besides mysql, so it's something that should really be unlearned

:)

r937.com | rudy.ca
 
Thanks fellers, I will try once I get home.

Sean.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top