Jump to content

Recommended Posts

I thought this was going to be a simple query, but i cant get the results i want from the query i am trying, please help.

 

Sample Data (3 tables)

Student Table

Student ID

Student Name

6239

Billy

6240

Linda

6241

Sam

 

ENROLLMENT TABLE

Student ID

Class ID

6239

1

6239

2

6239

3

6240

1

 

CLASS TABLE

Class ID

Class Name

1

Chemistry

2

English

3

Art

 

So from these three tables you can see that

Billy (6239) is enrolled in all 3 class

Linda (6240) is enrolled in Chemistry only

Sam (6241) is not enrolled in any classes at all.

 

The query i am trying to make is to find Sam, the student who is in my Student Table but not enrolled in any classes.

 

I thought the query would be something like this but of course didn't work...

 

SELECT *

FROM StudentTable, EnrollmentTable

WHERE StudentTable.StudentID != EnrollmentTable.StudentID

 

i also tried (but the same garbage results)

SELECT *

FROM StudentTable, EnrollmentTable

WHERE StudentTable.StudentID NOT LIKE EnrollmentTable.StudentID

 

 

so basically i am looking for and StudentID's from the Student Table that have no matches in the Enrollment Table.

 

Can anybody help please

 

Link to comment
https://forums.phpfreaks.com/topic/131721-how-to-find-find-data-that-doesnt-match/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.