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.

Hard Coding Foreign Key Values Instead of Joining to Lookup Tables in Queries

Rob JonesApr 19 2025

hi,

I'm using Oracle version 19c. We recently got into a discussion regarding joining transaction tables to lookup (parent) tables. One developer suggested that rather than joining the transaction table to a lookup table, hard code the actual foreign key value in the query rather than join to the lookup table to reduce performance risk. An example is below. Does anyone know of any pros/cons for either method? Only con of option 2 that I can of is that the foreign key ID values might be different between DEV and PROD.

--option 1 join to the department table
select emp.first_name,
       emp.last_name
from   employee emp
join   department dept
on     emp.department_id = dept.department_id
where  dept.department_name = 'Facilities'

--option 2 hard code id value for "Facilities" department
select emp.first_name,
       emp.last_name
from   employee emp
where  emp.department_id = 2 --id value for "Facilities"
Comments
Post Details
Added on Apr 19 2025
2 comments
179 views