Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 SQL Queries

Author  Topic 

eplam2
Starting Member

11 Posts

Posted - 2013-09-02 : 06:18:27
Say for instance I have 2 tables:

Subjects Students
--------- -----------
Teachers Initial Student's Initial
Teacher's Last Name Student's Last Name
Subject_code Subject_code

Ok, Im making this up..but lets say the two tables shown above have the following column names. Subject_code for the Subjects Table would be the primary key and the foreign key in the student's table. How can we use SQL Queries to check and make sure that both the Student's Initial is not the same with the Teacher's Initial. Likewise The Teacher's Last Name not the same with the Student's Last name?

Anybody has any idea?

Thank you!

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-02 : 07:53:43
SELECT s.*, st.*
FROM Subjects s
JOIN Students st
ON S.Subject_code = st.Subject_code
WHERE s.[Teachers Initial] != st.[student's Initial] AND s.[Teachers LastName] != st.[student's Last Name] -- This is for in-equality checking of initial & Last names of student As well as teacher....

--
Chandu
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-09-02 : 08:45:36
you either of them or both to be different?
If latter above suggestion would be sufficient
if former, you need OR instead of AND in WHERE

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

eplam2
Starting Member

11 Posts

Posted - 2013-09-02 : 08:48:50
nah, BOTH has to be different at the same time...
Go to Top of Page

eplam2
Starting Member

11 Posts

Posted - 2013-09-02 : 08:54:16
It worked! Thank you!~
Go to Top of Page

bandi
Master Smack Fu Yak Hacker

2242 Posts

Posted - 2013-09-03 : 05:29:29
quote:
Originally posted by eplam2

It worked! Thank you!~


Welcome

--
Chandu
Go to Top of Page
   

- Advertisement -