Naming columns from other tables

Course Queries Syllabus Queries 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Syllabus Queries related to Course Queries. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

Just a quick question about naming columns that come from other tables, below i have the tables put in the SQL statement but after it I put an abbreviated version "MO" is this correct/ will this work in all situations or should i just stick to the full version like module.mod_code?

SELECT MO.MOD_CODE, MO.MOD_NAME, MO.ECTS_UNITS,MO.DESCRIPTION
FROM MODULE MO, SYLLABUS SY, PROGRAMME PR
WHERE MO.MOD_CODE = SY.MOD_CODE
AND SY.PROG_CODE = PR.PRO_CODE
AND PR.NFQ_LEVEL = LEVEL 9
AND MO.DESCRIPTION LIKE ‘%RESEARCH%’ OR DESCRIPTION LIKE ‘%QUALATIVE%’ OR DESCRIPTION LIKE     ‘%QUANTITATIVE%’;

Thanks :)

profilepic.png
manpreet 2 years ago

 You cannot stick to the full version. Once you have given a table or subquery an alias, that is the name of that object in the scope of the query. Actually, what happens is that the table name becomesthe table alias, so you can use it for qualifying columns in the table.

You should also learn proper explicit JOIN syntax. I am also guessing that you are missing parentheses on your WHERE clause:

SELECT MO.MOD_CODE, MO.MOD_NAME, MO.ECTS_UNITS,MO.DESCRIPTION
FROM MODULE MO JOIN
     SYLLABUS SY
     ON MO.MOD_CODE = SY.MOD_CODE JOIN
     PROGRAMME PR
     ON SY.PROG_CODE = PR.PRO_CODE
WHERE PR.NFQ_LEVEL = 'LEVEL 9' AND
      (MO.DESCRIPTION LIKE '%RESEARCH%' OR
       MO.DESCRIPTION LIKE '%QUALATIVE%' OR
       MO.DESCRIPTION LIKE '%QUANTITATIVE%'
      );

If you attempted something like SELECT MODULE.MOD_CODE in this query, it would return an error, because the table alias MODULE is not assigned to any object.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.

tuteehub community

Join Our Community Today

Ready to take your education and career to the next level? Register today and join our growing community of learners and professionals.

tuteehub community