File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JDBC and the fly likes Duplicate recs in SQL Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Databases » JDBC
Reply Bookmark "Duplicate recs in SQL" Watch "Duplicate recs in SQL" New topic
Author

Duplicate recs in SQL

Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Just wondering if there is a SQL guru out there that might be able to help.

I have a SQL statement that is roughly.

The problem is the codes (EINA, EINE, and EINV) are permissions and a user can have more than one permission. If I don't have T312.CODE in the SELECT and GROUP BY the sum is multiplied by the number of permissions, if I do put the T312.CODE in the SELECT and GROUP BY I get extra rows for multiple permissions.

Is there a way to change the IS to a 'if you find one, great stop looking', also if this is possible is there a way to order how it looks (ei will find EINA before EINV or something).

Thanks.
Paul Sturrock
Bartender

Joined: Apr 14, 2004
Posts: 10336

The easiest way is 3 seperate queries.


JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Jeanne Boyarsky
internet detective
Marshal

Joined: May 26, 2003
Posts: 26144
    
  66

Originally posted by Steven Bell:
Is there a way to change the IS to a 'if you find one, great stop looking', also if this is possible is there a way to order how it looks (ei will find EINA before EINV or something).

No. The best you could do is sort and limit the number of rows returned. But this wouldn't stop the database from performing the whole query. I agree with Paul that you would be better served with separate queries.


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
Steven Bell
Ranch Hand

Joined: Dec 29, 2004
Posts: 1071
Thanks, I was able to split it up into two seperate queries.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Duplicate recs in SQL
 
Similar Threads
Hibernate Hell
SQL question
SQL Performance Tuning - Release Announcement - Addison-Wesley
Sum function sql statement
SQL : Aggregate functions and Group By clause