AND conditions in SQL Server
In SQL Server, the AND condition (or AND operator) is used to test two or more conditions in SELECT, INSERT, UPDATE, or DELETE statements.
AND condition syntax
WHERE 'điều kiện 1'
AND 'điều kiện 2'
…
AND 'điều kiện n';
Variable name or variable value
Condition 1, condition 2 . conditions n
The conditions that the record must meet to be selected.
Note
- The AND condition in SQL Server allows two or more conditions to be checked.
- The AND condition in SQL Server requires that all conditions be met and the new record is included in the result set.
For example - with SELECT statement
SELECT *
FROM nhanvien
WHERE ho = 'Smith'
AND nhanvie
n_id <499;
The result in this example will return all employees with the surname Smith and nhanvien_id less than 499. Because * is used in the SELECT statement, all fields in the table are in the result set.
Example - table combination
SELECT nhanvien.nhanvien_id, danhba.ho
FROM nhanvien, danhba
WHERE nhanvien.nhanvien_id = danhba.danhba_id
AND nhanvien.ten = 'Sarah';
Although the above example still works, it will usually need to be written in INNER JOIN.
SELECT nhanvien.nhanvien_id, danhba.ho
FROM nhanvien
INNER JOIN danhba
ON nhanvien.nhanvien_id = danhba.danhba_id
WHERE nhanvien.
ten = 'Sarah';
In this example, the returned result will include all the rows with the employee's name as Sarah in the table. Table of names and names connected by nhienvien_id and danhba_id.
Note that all information fields are named after the table name (eg danhba.ten). This is required, to avoid ambiguity about the referenced information field, for example, when two tables have the same information field.
In this case, the returned result will only be displayed with the_id and cough.
Example - INSERT command
INSERT INTOdanhba
(danhba_id, ho, ten)
SELECT nhanvien_id, ho, ten
FROM nhanvien
WHERE ten = 'Joanne'
AND nhanvien_id >=
800;
The AND condition in this example will insert the list of all fields, ten, and coughs from the table with those named Joanne and nhanvien_id greater than or equal to 800.
Example - UPDATE command
UPDATEanvien
SET ho = 'Johnson'
WHERE ho = 'TBD'
AND nhanvien
_id <300;
This example will update all the values in the table to Johnson when the employee's surname is valued as TBD and nhanvien_id less than 300.
Example - DELETE command
DELETE FROM nhanvien
WHERE ten = 'Darlene'
AND ho = 'Hend
erson';
This command will delete all records in the table if the employee is named Darlene and they are Henderson.
Previous article: ORDER BY clause in SQL Server
Next article: OR conditions 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.