Q
Problem solve Get help with specific problems with your technologies, process and projects.

Getting counts, displaying distinct columns from a million rows

Which is the faster way to get counts and display the distinct column lists from the million rows:

1. Get distinct column lists:
    select count(*)
    from (
    select distinct
       empno, ename, deptname
    from employee e, department d
    where e.deptno = d.deptno )

2. Display the columns:
    select distinct
       empno, ename, deptname
    from employee e, department d
    where e.deptno = d.deptno
Can I combine them into one or is there any other way to speed up performance? Thanks for your help.

You can combine information by using GROUP BY with COUNT to get what you want.

Add indexes on the grouped columns to the tables in order to speed up retrieval.

Do this:

  select empno, ename, deptname,count(*)
   from employee e, department d
   where e.deptno = d.deptno
   group by empno, ename, deptname
You'll get your info the fastest way, and GROUP BY will take care of the distinct.

For More Information


Dig Deeper on Oracle and SQL

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchDataManagement

SearchBusinessAnalytics

SearchSAP

SearchSQLServer

TheServerSide.com

SearchDataCenter

SearchContentManagement

SearchHRSoftware

Close