SQL Training Online

  • Training Courses
  • Beginner Book
  • Blog

June 12, 2012 by Joey Blue Leave a Comment

Troubleshooting a SQL Join

I shot a training video today while I was answering a SQL Join question on Yahoo Answers.

During the video, I construct the database, tables, and example data.

Then I tried to run the current query to see what error I get.  Finally, I work through the issue and fix the join.

Here is the video:

If you couldn’t see the question well in the video, here is a reprint.

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.

http://answers.yahoo.com/question/

My answer is to put in the inner join condition.

Here is the final query:

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; 

I am attaching the script to create and populate the tables and the Microsoft Excel file so you can see how I create my INSERT statements.

SqlTrainingOnlineUniversityDB.zip

Let me know if you have any questions or comments by posting them below.

Filed Under: SQL Training Tagged With: Demo Database Setup, SQL Join, Yahoo Answer

Recent Posts

  • SQL Database Normalization – 1NF, 2NF, 3NF, and 4NF
  • SQL Joins Tutorial for Beginners – Inner Join, Left Join, Right Join, Full Outer Join – SQL Training Online
  • Zillow House Price Analysis from CSV Archive – #PowerBI 002
  • Learn Basic SQL – 1 Hour Training Course – SQL Training Online
  • Create Table Statement in SQL Server and Inserting Baseball Homerun Leader Dataset – SQL Training Online

Popular Posts

  • SQL Functions
  • SQL Jobs in Oracle and Microsoft SQL Server
  • Troubleshooting a SQL Join
Copyright © 2023 · SQLTrainingOnline.com · Consulting at EmbarkBlue.com