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!

Comparing Data to multiple rows in a table - Based on primary key

Jeremy McNallyJul 8 2015 — edited Jul 14 2015

Currently, I have a select statement which returns hundreds of records.  Each record returned is tied to ORDER NUMBER A.  This Order Number A has a recipe.  (kind of like a food recipe).  Each recipe has many records in the database pertaining to this order number and those records need to be compared to records in a table that tie to a specific primary key...  (I already developed the logic to single out what PK I need).  If all those records returned from the select statement below doesn't match all the records that PK holds in the table below, I need to get the next PK and compare all those records to the select statements return. 

See below for a better understanding.  In need of a good detailed example on how to resolve my issue here.

Just to help you understand:

Each item in the recipe has 3 parts to it (side, ref_des, part_number).  1 single recipe can have many parts (hence the part_number), and each of those parts need to be placed on either the Bottom side or Top side of a board which is where "Side" comes into play.  Same with Ref_Des.  

WHAT IS HAPPENING

Select statement is returning the RECIPE of ORDER NUMBER A.  There will be multiple records returned by this query.

Select Statement Return:

  • Side                                                        
  • Ref_Des
  • Part_Number

Example of Return:

B     c17    75145-2

T     f14     89242-8

B    s12     45123-3

etc,,,,

Generally Speaking - what I need to do:

There is a table called AUTO_RECIPE_DETAILS.  I have to take all the records returned by the above select query and compare them to every record in this table pertaining to recipe 30319-000001.  30319-000001 has many records.  That is the primary key for an entire recipe like you see above.  That primary key is associated to many records of data in this table.  The comparison is to see if all the records under RECIPE_NAME 30319-000001 match all the records returned by the above select statement. 

IF IT DOES NOT MATCH:  get the next recipe in this table below 30319-000002 and do the same comparison. 

 

Here is a perfect example of what the table looks like: (AUTO_RECIPE_DETAILS)


RECIPE_NAME         SIDE            REF_DES            PART_NUM

- 30319-000001            B                   C16                       87595-1

- 30319-000002             T                   B14                       74150-4

- 30319-000001            T                   B14                       34251-2

- 30319-000001            T                   F24                       84180-7

- 30319-000002            T                   B12                       13710-8



This post has been answered by Jeremy McNally on Jul 14 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2015
Added on Jul 8 2015
22 comments
4,779 views