Database SQL query issues?

I have developed the database with the following tables:

STUDENT

S_ID PRIMARY KEY

S_FNAME

S_LNAME

S_ADDRESS

S_CITY

S_STATE

S_ZIPCODE

S_PHONE

SCHOLARSHIPS

S_ID PRIMARY KEY FOREIGN KEY REFERENCES STUDENT

SC_MAJOR

SC_ACADEMIC

SC_ATHLETIC

GPA

S_ID PRIMARY KEY FOREIGN KEY REFERENCES STUDENT

G_GPA

G_CLASS /*(4 is for Seniors)*/

I then inputted data and did the following SQL query:

SELECT S_ID, S_LNAME, S_FNAME, S_ADDRESS, S_CITY, S_STATE, S_ZIPCODE, S_PHONE

FROM STUDENT

WHERE GPA.G_CLASS = 4

ORDER BY S_LNAME, S_FNAME;

I get the following error:

The data content could not be loaded. Column not found: GPA.G_CLASS.

Please assist with any tutoring or assisting. Thank you.

5 Answers

Relevance
  • 8 years ago
    Favorite Answer

    You're not joining STUDENT with the GPA table. You need to add the additional tables you need data from as well as the tables you need to perform your join:

    ...FROM student,gpa...

    You also need a join condition:

    WHERE student.id=gpa.student_id

    or something like that.

  • 8 years ago

    The only table in your FROM is STUDENT. If you want to refer to a column in another table in your query, it has to appear in the FROM (and should be related to the other tables in some way, either thru a JOIN or via the WHERE clause.)

  • 8 years ago

    You need to add the GPA table to your FROM clause.

    The query should look like this:

    SELECT STUDENT.S_ID, S_LNAME, S_FNAME, S_ADDRESS, S_CITY, S_STATE, S_ZIPCODE, S_PHONE

    FROM STUDENT inner join GPA on STUDENT.S_ID=GPA.S_ID

    WHERE GPA.G_CLASS = 4

    ORDER BY S_LNAME, S_FNAME;

  • 3 years ago

    you're able to desire to question in those 3 tables you have reported; subject table, customer table, e book table. on condition that each and every table has a distant places key for another, there must be no situation getting access to documents which will tournament your question. right this is what i think of your question must be: pick customer_name, book_name from issue_table a, customer_table b, book_table c the place a.customer_id = b.customer_id and a.book_id = c.book_id desire this helps. additionally, please be conscious which you will might desire to apply aliases on your tables so sq. could be attentive to in what particular table ought to it get the IDs on your the place clause given which you have comparable column names for various tables.

  • How do you think about the answers? You can sign in to vote the answer.
  • Anonymous
    8 years ago

    You forgot inner join

    FROM STUDENT INNER JOIN GPA ON STUDENT.ID = GPA.S_ID

    WHERE ...

Still have questions? Get your answers by asking now.