Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
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

Win a copy of OCA Java SE 8 Programmer I Study Guide 1Z0-808 this week in the OCAJP forum!
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: 3732

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]
It is sorta covered in the JavaRanch Style Guide.
subject: Oracle Query