Conditions NOT in SQL Server
The NOT condition in SQL Server (Transact-Server) is also called the NOT operator, which is used to negate conditions in SELECT, INSERT, UPDATE, and DELETE statements.
Syntax of NOT condition
NOT 'điều kiện'
Variable name or variable value
condition
Conditions must be negative.
Note
The NOT condition requires that the record be contrary to the 'condition' to be returned in the result set.
Example - combined with IN conditions
SELECT *
FROM nhanvien
WHERE te
NOT IN ('John', 'Dale', 'Susan');
This example will return all rows from the nhanvien table whose name is not John, Dale or Susan. Sometimes finding values that are not worth looking for is faster.
For example - combine condition IS NULL
This is an example of a combination of NOT and IS NULL conditions in SQL Server.
SELECT *
FROM nhanvien
WHERE ho IS NOT NULL;
The returned result is all records in the table nhanvien that they contain no NULL value.
Example - combine LIKE condition
Combine LIKE and NOT to find values against what you want.
SELECT nhanvien_id, ho, ten
FROM nhanvien
WHERE ho NOT LIKE 'A%';
When placing the NOT operator before the LIKE condition, the result will be for employees whose last name does not start with the letter 'A'.
For example - combine BETWEEN conditions
SELECT *
FROM nhanvien
WHERE nh
anvien_id NOT BETWEEN 200 AND 250;
In this example, the returned result is the rows in the employee table that have nanvien_id not in the range of 200 and 250, including both the first and last values. It will be equivalent to the SELECT command below.
SELECT *
FROM nhanvien
WHERE nhanvien_id < 200
OR nhanvien
_id> 250;
For example - combine EXISTS conditions
SELECT *
FROM nhanvien
WHERE NOT EXISTS (SELECT *
FROM danhba
WHERE nhanvien.ho = danhba.ho
AND nhanvi
en.ten = danhba.ten);
The command in the example above will return records from the table of names if there is no record in the list with the first and last names.
Previous article: Conditions LIKE in SQL Server
Next lesson: ALIAS in SQL Server
You should read it
May be interested
- Network basics: Part 3 - DNS Servera dns server is a server that contains a database of public ip addresses and hostnames associated with them. in most cases, the dns server is used to resolve or translate those common names into ip addresses as required.
- How to set up your own Git server on Linuxwhile you can count on globally renowned git hosting services like github, in some cases it is better to host a personal git server for enhanced privacy, customizability, and security.
- Use IIS to set up FTP Server on Windowsset up an ftp server (file transfer protocol server) to share and convert large files with unlimited traffic.
- How to change DNS server on the most popular routerschanging the dns server settings on your router is not difficult, but every manufacturer uses their own custom interface, which means the process can be very different depending on which router you are owned.
- What is VPS? VPS used to do? What is VPS different from Server?what is vps? vps used to do? what is vps different from server ?. when you intend to learn about network data or open the website, you will definitely be introduced to many different server and server services. but server hosting has a lot of tricks
- 7 great ideas using Raspberry Pi as a serverraspberry pi is a great solution for many computer projects, from learning programming to remote control a car to building a basic stop-motion animation studio. but do you know that raspberry pi can also be used as a server? here are some ideas for using raspberry pi as a server.
- New points in SQL Server 2017the sql server 2017 version is primarily connected to linux, bringing the power of sql to linux. in short, you can install sql server 2017 on linux, using sql server 2017 on linux-based docker containers. sql server 2017 also allows you to choose development languages, develop it on-premise or cloud-based.
- Instructions for setting up and managing FTP Server on Windows 10if you want to create a private cloud for sharing and converting large files without restrictions, you can create an ftp server (file transfer protocol server) on your windows 10 computer.
- Create VPN Server on Windows 8no need to install any additional applications, you can easily 'turn' your computer into a vpn server if you're using windows 8. in this way, you can share data from the computer. as a simple lan system in the form of remote access. & a
- What is the future of server virtualization?server virtualization can help combat poor server performance, make better use of computing capabilities, limit energy consumption and improve data center flexibility.