8/27/2023 0 Comments Not equal to in sql server![]() SELECT StID FROM StudentExam WHERE ExamName='SQL Server' To produce the correct report, you can simply use a subquery to build the list of students who have taken SQL Server exam: If the relationship between Students and StudentExam was one-to-one (each student could take only one exam), the previous query would work fine. Basically you must take care of this problem when dealing with one-to-many joins. The subtle reason of this is that Jack still satisfies the WHERE clause because of his second exam, XML! This exam causes the WHERE clause return "True" when he is being checked by the condition. Note that although Bob did not appear in the result because he has not taken any exam to satisfy an INNER JOIN, again Jack is there! The first thing that might come to mind is replacing the "Equal" operator in WHERE clause with "Not Equal To" operator: Well, everything is OK so far, but the issue turns up when we are asked to query the students who have NOT taken SQL Server exam. Now we are asked to prepare a report that lists information of students who have taken SQL Server exam: In a perfect design, we would need another table called Exams which stores the full specifications of each exam, but I have denormalized it with StudentExam table for the sake of simplification. INSERT StudentExam VALUES (1,'SQL Server') Let's create the required tables and populate them with some rows: Obviously each student can take more than one exam. Here is an example: Suppose that a Testing Center registers students for IT exams. The "Not Equal To" () operator is useful when you need to filter your data and exclude some rows from the result of query, but there are cases that when you really mean Måolumn'SomeValue', you should not use this operator in order to get the correct result! The Pitfall of "Not Equal To" operator in queries! INTRODUCTION
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |