It's not a secret anymore!
The moose likes JDBC and Relational Databases and the fly likes Oracle Query Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
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: 3753

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 ]

[OCA 8 Book] [Blog]
I agree. Here's the link:
subject: Oracle Query
It's not a secret anymore!