-2

Courses

Instructors

Sections

Students

StudentSchedule

StudentSchedule Part 2

Using the database provided, Write and Execute SELECT statements to get the following information:

SIMPLE JOINS

Sections Table

  1. How many total credit hours is instructor 6 teaching?

What I tried:

select sum(c.credithours) 
from courses c
join sections s on c.courseid = s.courseid
join instructors i on s.instructor = i.ID
                   and s.instructor = 6; 

ERROR:

Syntax error in FROM clause

  1. Please give the CRN, Course Name, description and credithours, timedays and roomno for all the courses being taught in room 1147. Are there any conflicts?

What I tried:

select CRN, CourseName, description, credithours, timedays, roomno
from courses c
join sections s on c.courseid = s.courseid
join instructors i on s.instructor = i.ID
                   and roomno = "F1147";

ERROR:

Syntax error in FROM clause

StudentSchedule Table

  1. Give a list of Student Names and IDs that are signed up for the section with CRN=30101. (List Student’s first name, last name, ID and CRN)

What I tried:

select firstname, lastname, ID, CRN 
from studentschedule ss
join students s on ss.student_id = s.id
                and CRN = 30101;

ERROR:

Syntax error in FROM clause

  1. Please list all the student names(first and last) that are in the section with CRN=30115.

What I tried:

select firstname, lastname, ID, CRN 
from studentschedule ss
join students s on ss.student_id = s.id
                and CRN = 30115;

ERROR:

Syntax error in FROM clause

  1. Please list all section information for all the sections that are being attended by Student with id=6.

What I tried:

select s.* 
from studentschedule ss
join sections s on ss.CRN = s.CRN
                and studentid = 6;

ERROR:

Syntax error in FROM clause

  1. Advanced(Multiple tables): Please list the name of the course, the CRN and the Names of all the students that are in the section with CRN=30115.

What I tried:

select firstname, lastname, ID, CRN, coursename
from studentschedule ss
join students s on ss.student_id = s.id
join sections sec on ss.CRN = sec.CRN
join courses c on sec.courseid = c.courseid
               and CRN = 30115;

ERROR:

Syntax error in FROM clause

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Marc
  • 1
  • 3
  • 1
    Hi. Please [use text, not images/links, for text (including code, tables & ERDs)](https://meta.stackoverflow.com/q/285551/3404097). Use a link/image only for convenience to supplement text and/or for what cannot be given in text. And never give a diagram without a legend/key. Use edit functions to inline, not links, if you have the rep--make your post self-contained. Please act on [mcve]. Please ask one question per question. Show what parts & relevant queries you can do correctly & ask a specific question about where you are stuck. See edit help re formatting text. Chop code until correct. – philipxy Nov 06 '18 at 03:25
  • 1
    You really ask that all question in 1 question? – dwir182 Nov 06 '18 at 04:02
  • The queries look okay on a quick glance. `Syntax error in FROM clause` is a very broad error message. Is this really all you get? Which DBMS are you using? It should be much more explicit in its messages. – Thorsten Kettner Nov 06 '18 at 07:06
  • 1
    Double quotes are for delimited identifiers. Do you have a column named `"F1147"`, or are you searching for the `'F1147'` string value. – jarlh Nov 06 '18 at 07:48
  • Please read [ask] & the downvote arrow mouseover text & hits googling 'stackexchange homework'. A google of your error message with 'site:stackoverflow.com' gives many appropriate answers. – philipxy Nov 08 '18 at 02:58
  • Possible duplicate of [Access query error (“syntax error in from clause”)](https://stackoverflow.com/q/18967627/3404097) – philipxy Nov 08 '18 at 03:00

1 Answers1

-2

Access does not have JOIN on it's own.

You must use INNER JOIN, LEFT JOIN or RIGHT JOIN - or you will get that error.

for example: the solution to question 1 would be:

SELECT Sum([CreditHours]) AS totalHours
FROM Courses INNER JOIN Sections ON Courses.CourseID = Sections.CourseID
WHERE (((Sections.Instructor)=6));

note that you don't need the instructor table at all for this one, unless they ask for name or other details about the instructor.

also note: I wouldn't worry about optimizing using short table names on such a simple query.

trevor
  • 257
  • 3
  • 9
  • This answer makes hardly any sense. As we can clearly see, Marc is joining the tables with `JOIN`. This is short for `INNER JOIN`. – Thorsten Kettner Nov 06 '18 at 07:09
  • I have ten years experience with Microsoft Access... If you just put JOIN instead of INNER JOIN - the error you get is: "Syntax Error in FROM clause" - with that case and all. If you note the brackets in my answer - I cut this code from the working query in Access - please check before you downvote - it's not nice. – trevor Nov 06 '18 at 22:51
  • 1
    I have downvoted this answer as misleading. This is what the downvote arrow is for. Your question whether Marc jojned the tables indicated that you didn't look at his queries. Recommending to use `INNER JOIN` instead of `JOIN` didn't make sense, because `JOIN` is short for `INNER JOIN`. And then you posted an invalid SQL query (according to standard SQL that is). Now you are telling me, that you assume that Marc uses MS Access and this is what the errors stem from. But you don't mention this in your answer. (You could have asked for the DBMS used in the request comment section by the way.) – Thorsten Kettner Nov 07 '18 at 06:40
  • 1
    You may want to update your answer to something like "Your queries look fine. From the error message you are getting, I deduce you are using MS Access. This DBMS doesn't comply to the SQL standard at all and requires special syntax. For instance, unlike other DBMS MS Access requires you to spell out `INNER JOIN` instead of using just `JOIN`. It is violating the SQL standard in this and many other points. I suggest you use another DBMS for learning. Otherwise you would have to rewrite most queries you are writing or find on the Internet. Here is your first query rewritten to MS Access SQL: ..". – Thorsten Kettner Nov 07 '18 at 06:40
  • Change your answer to something like that and I'll remove my downvote. – Thorsten Kettner Nov 07 '18 at 06:41
  • Read [ask] & [answer] (etc) & the comments on the question for some info on why people might downvote this. Please do not answer duplicate, unclear or close-worthy questions. – philipxy Nov 08 '18 at 02:54