0

Hi, I have a question regarding a SQL query. I am a complete noob, so please do not make fun of me.

Here is a schema that I created:

JOURNALS(j_num, j_name, j_subject_area, chief_editor_r_ssn)
ISSUES(j_num, i_num, i_date, i_num_pages)
RESEARCHERS(r_ssn, r_name, r_address, r_phone, r_institution)
ARTICLES(art_num, art_title, art_area_topic, art_abstract, j_num_submitted,date_submitted, j_num_published, i_num_published)
AREA_EDITS(j_num, r_sssn)
WRITES(r_ssn, art_num)
REVIEWS(r_ssn, art_num)
RESEARCH_SPECIALTIES(r_spec_name)
RRS(r_ssn, r_spec_name)

It's pretty simple. My question is regarding the linking of the primary keys. Is it necessary to link the primary keys if I were doing something like: The number of journals for which researcher ‘Albert Einstein’ is the chief editor?

The SQL query I came up with is:

SELECT count (*), j.j_num
FROM journals as J, Researchers as R, Area_edits as AE
WHERE J.chief_editor_r_ssn=R.r_ssn
AND R.r_name="Albert Einstein"
AND R.r_ssn=AE.r_ssn
AND J.j_num=AE.j_num;

Is it necessary to include the last 2 steps, or are the unneeded?

Edited by __avd: Add [code] tags. Encase your code in: [code] and [/code] tags.

2
Contributors
2
Replies
3
Views
7 Years
Discussion Span
Last Post by J3vr0N
0

Unneeded; because you require j_num from the journals tables you are already linking the table with researchers table. That join should suffice to return the information you required. If you wanted to return a value from the Area_Edits table then the second join would be necessary, the last join is completely unnecessary.

0

Unneeded; because you require j_num from the journals tables you are already linking the table with researchers table. That join should suffice to return the information you required. If you wanted to return a value from the Area_Edits table then the second join would be necessary, the last join is completely unnecessary.

Thank you very much for your help. That's what I figured, I was just unsure.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.