Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Count(*) , group by with multiple columns from multiple tables involved

569503Mar 28 2007 — edited Mar 28 2007
Hi all,

I am relatively new to SQL.
Currently I have these few requirements, to display quite a number of fields from 3 tables for display of report.

In my query I need to:
1.) count(*)
2.) select quite a number of fields from table 1,2,3

However when count(*) is used, grouped by has to be used to.
How do I actually use group by with so many columns to be selected?

I have actually used the query below, but the count(*) returns 1, the correct output should be 3 instead.

select count(*), table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5
from table1, table2, table3
where
<conditions>........................
group by table1.col1, table1.col2, table1.col3, table2.col3, table2.col4, table2.col6, table3.col1, table3.col4, table3.col5

I know this group by statement looks very unrefined. How can I select multiple fields from different tables, and yet get the count(*) correctly?

Thank you so much for your time.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 25 2007
Added on Mar 28 2007
5 comments
699 views