wood burning stoves 2.0*
The moose likes JDBC and the fly likes Oracle Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Databases » JDBC
Bookmark "Oracle Query" Watch "Oracle Query" New topic

Oracle Query

mash john

Joined: Sep 04, 2005
Posts: 15
I have a parent table named Track_locations with org_roadmark and track_location_id as primary keys.

I have 2 child tables online_equip and unload_list_equip with track_location_id,org_roadmark as foreign keys.

I need to retrieve the total count of track_location_id present in both(or either of ) the child tables in a single query.
Scott Selikoff
Saloon Keeper

Joined: Oct 23, 2005
Posts: 3703

Select the count of each using count(*) in the SQL query and then add the results which can also be done in the same SQL statement. Depending on your grouping requirements though, you might get duplicates (for example if the same parent reference appears in both child tables).

Again, your requirements would dictate how to proceed, but if you need the count to be for non-overlapping parents, the UNION command could also help.
[ December 19, 2005: Message edited by: Scott Selikoff ]

My Blog: Down Home Country Coding with Scott Selikoff
I agree. Here's the link: http://aspose.com/file-tools
subject: Oracle Query
Similar Threads
To identify Primary Keys in a table
Hibernate : Hibernate :Mapping Multiple Table for single POJO class
Getting the Keys in a Resultset
Best way to join a parent with many child tables yet preserving all parent table rows
Many to Many with out primary keys