Here, I will display a list of all employees with an exception to exclude those employees who belong to a specific city “London” and are working at the specific position like “Analyst” SELECT Name, City, Age, Designation Where Designation != ‘Manager’ List all Employees Excluding from a Specific Location and Designation SELECT Name, Designation, s.Product, s.Price You will get the same output if you run the below query having another Not Equal To operator (!=). We can see employees and their sales details except those who are working as managers. Finally, I’ve applied a filter on the designation column with the Not Equal To operator to exclude all employees who are working at the Manager designation. I have joined two tables to get employee names & designation from the employee table and product & invoice details from another table Sales. Let’s take the first use case in which I will fetch the sales details of all employees except those who are working in the Manager position. ![]() Display a Sales Report of All Employees except Those Working on a Specific Designation Let’s explore them using several examples. Here I will show you a few use cases of Not Equal To operator using both symbols. USE Cases of the Comparison Operator Not Equal To You can see the output of the above two queries which is the same showing in the below image. I will run the below statements to get the result of our requirements. I want to search for all employees who are not working on contract or whose employment nature is not equal to 5. Now, let me go ahead with a use case with help of an example. These both operators will return the same output but if you are using NULL either on the left-side or right-side expression or on both sides while using the != operator, you will be getting the output as NULL only whereas if you use with NULL at any place left or right or both places then output depends on ANSI_NULLS settings We can see there are two different symbols for the Not Equal To operator shown in the comparison operator column of the above table. If you look at the above example for the Not Equal To operator, it means to list all employees whose age is Not Equal To 45. ! or !=) operator tests one expression is not equal to another expression, we can also say the left-side expression is not equal to the right-side expression of the Not Equal To operator symbol. ![]() You might also observe that some of the operators have more than one symbol. Here is the list of those symbols we use while doing any comparison between expressions. ![]() All these operators have their respective symbols which we use in SQL statements. SQL Server has offered multiple operators for various comparisons like equal to, greater than, less than, not equal to, less than or equal to, greater than or equal to. This article will give an overview of the SQL Not Equal To operator and demonstrate how to use it in your queries requirements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |