[Solved] Using WHERE changing column results in queries

Creating tables and queries
Post Reply
DatabaseNewbie
Posts: 6
Joined: Sat Jan 07, 2023 5:12 am

[Solved] Using WHERE changing column results in queries

Post by DatabaseNewbie »

I'm working on a project where I have two tables. One is the students' information (names, phone number, address, etc.). The other table is the GPA scores and class (Freshman, Sophomore, Junior, etc.).

I'm supposed to generate a table where I pull the students' information based on them being a Senior. I'm somewhat familiar with SQL commands, but I'm still having trouble.

The problem with my query is that the resulting table will pull the students' information (for all 7 students) and change all their Class input to 'Senior' instead of just pulling the students' information for those who are actually Seniors (only 2 students) based on the GPA table.

Below are my SQL commands. Can anyone help me figure out what is wrong with it?

Please note that my primary key is StudentNumber because it appears in both tables. Not sure if I need to use that to get the desired result.

SELECT DISTINCT "StudentTable"."FirstName", "StudentTable"."LastName", "StudentTable"."Address", "StudentTable"."City", "StudentTable"."State", "StudentTable"."Zipcode", "StudentTable"."Phone", "GPATable"."Class"
FROM "StudentTable", "GPATable"
WHERE "GPATable"."Class" IN ( 'Senior' )
Last edited by Hagar Delest on Sat Jan 07, 2023 8:10 pm, edited 1 time in total.
Reason: tagged solved.
OpenOffice Version 4 on Mac Ventura
FJCC
Moderator
Posts: 9284
Joined: Sat Nov 08, 2008 8:08 pm
Location: Colorado, USA

Re: Using WHERE changing column results in queries

Post by FJCC »

Try
SELECT DISTINCT "StudentTable"."FirstName", "StudentTable"."LastName", "StudentTable"."Address", "StudentTable"."City", "StudentTable"."State", "StudentTable"."Zipcode", "StudentTable"."Phone", "GPATable"."Class"
FROM "StudentTable" INNER JOIN "GPATable" ON "StudentTable"."StudentNumber" = "GPATable"."StudentNumber"
WHERE "GPATable"."Class" IN ( 'Senior' )
OpenOffice 4.1 on Windows 10 and Linux Mint
If your question is answered, please go to your first post, select the Edit button, and add [Solved] to the beginning of the title.
DatabaseNewbie
Posts: 6
Joined: Sat Jan 07, 2023 5:12 am

Re: Using WHERE changing column results in queries

Post by DatabaseNewbie »

That worked just great! Thank you!
OpenOffice Version 4 on Mac Ventura
Post Reply