Foreign key referencing | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Foreign key referencing

Please a table has a foreign key but I need to use a different column in that table For calculation in another table as a column its own please how do I go about it Hope the question is understood

28th Aug 2020, 11:37 AM
esther iyege
esther iyege - avatar
4 Answers
+ 2
No, the foreign key column from the second table does not have to be used in the calculation. Here is a sample of what I think your query might look like: SELECT (tbl1.col3*tbl2.col3) AS NewCol FROM tbl1 LEFT JOIN tbl2 ON tbl2.col2 = tbl1.col4;
28th Aug 2020, 12:43 PM
Brian
Brian - avatar
+ 4
Before I answer, let me reflect what I understand: you have two tables joined on a foreign key. You wish to use a field from the first table and a field from the second table to perform a calculation, and assign a new column name to the result. Is this accurate?
28th Aug 2020, 12:16 PM
Brian
Brian - avatar
+ 1
First I need to reference a column in another table but the column I need to reference is not a primary key and I am required to use that column for calculation in the referenced table. Please do you understand the question now?
28th Aug 2020, 12:28 PM
esther iyege
esther iyege - avatar
+ 1
Thanks
28th Aug 2020, 12:44 PM
esther iyege
esther iyege - avatar