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.
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 InitialTeacher's Last Name Student's Last NameSubject_code Subject_codeOk, 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 sJOIN Students stON S.Subject_code = st.Subject_codeWHERE 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 |
 |
|
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 sufficientif former, you need OR instead of AND in WHERE------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs |
 |
|
eplam2
Starting Member
11 Posts |
Posted - 2013-09-02 : 08:48:50
|
nah, BOTH has to be different at the same time... |
 |
|
eplam2
Starting Member
11 Posts |
Posted - 2013-09-02 : 08:54:16
|
It worked! Thank you!~ |
 |
|
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 |
 |
|
|
|
|