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.deptnoCan 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.
select empno, ename, deptname,count(*) from employee e, department d where e.deptno = d.deptno group by empno, ename, deptnameYou'll get your info the fastest way, and GROUP BY will take care of the distinct.
For More Information
- Dozens more answers to tough Oracle questions from Eli Leiba are available here.
- The Best Oracle Web Links: tips, tutorials, scripts, and more.
- Have an Oracle or SQL tip to offer your fellow DBAs and developers? The best tips submitted will receive a cool prize. Submit your tip today!
- Ask your technical Oracle and SQL questions -- or help out your peers by answering them -- in our live discussion forums.
- Ask the Experts yourself: Our SQL, database design, Oracle, SQL Server, DB2, metadata, object-oriented and data warehousing gurus are waiting to answer your toughest questions.
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.