Mặc dù hầu hết các ứng dụng sẽ có một số dạng công nghệ phía máy chủ hoặc thậm chí phía máy khách có thể được sử dụng để lọc ra các kết quả truy vấn cơ sở dữ liệu có thể chứa
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3 hoặc các giá trị trống, nhưng việc sử dụng ngôn ngữ khác và gánh nặng thực thi mã bổ sung đó thường tốn kém hơn cho Thay vào đó, bên dưới chúng ta sẽ khám phá ngắn gọn cách sử dụng chính công cụ MySQL để thực hiện tác vụ này, chỉ lấy các bản ghi mà bạn mong muốn trong khi loại trừ những bản ghi có cột
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3 phiền phức trong hỗn hợpIS NOT NULL Toán tử so sánh
Cho đến nay, phương pháp đơn giản và dễ hiểu nhất để đảm bảo một tập hợp kết quả cột cụ thể không chứa giá trị ________ 13 là sử dụng toán tử so sánh
Ví dụ: nếu chúng tôi muốn chọn tất cả các bản ghi trong bảng
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
6 trong đó cột id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
7 không phải là id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3, thì truy vấn có thể trông như thế nàySELECT
primary_author,
published_date,
title
FROM
books
WHERE
primary_author IS NOT NULL;
Vì
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
9 hoạt động giống như bất kỳ bộ so sánh nào khác, nên nó có thể được kết hợp với các mệnh đề id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
1 khác để lọc thêm kết quả, giống như khi bạn đang sử dụng id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
2, id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3, id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
4, id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
5 và các toán tử so sánh tiêu chuẩn khácLọc NULL từ nhiều cột
Trong một số trường hợp, bạn có thể muốn truy xuất kết quả khi không có giá trị
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3 nào trên nhiều cột. Ví dụ: chúng tôi có một số bản ghi trong bảng id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
6id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
Hãy lưu ý rằng The Doors of Stone [
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
8] chưa được xuất bản và do đó, id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
9 là id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3. Tương tự, Beowulf [SELECT
primary_author,
published_date,
title
FROM
books
WHERE
[
primary_author IS NOT NULL
AND
published_date IS NOT NULL
];
1] – thiên anh hùng ca cổ nổi tiếng của Anh – không rõ tác giả, vì vậy id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
7 là id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3Trong trường hợp này, chúng tôi có thể muốn truy vấn các kết quả chỉ chứa bốn bản ghi đầu tiên, do đó loại trừ hai bản ghi cuối cùng có giá trị
id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
3 trong id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
7 hoặc id | title | primary_author | published_date
1 | The Hobbit | Tolkien | 09-21-1937
2 | The Silmarillion | Tolkien | 09-15-1977
3 | The Name of the Wind | Rothfuss | 03-27-2007
4 | The Wise Man's Fear | Rothfuss | 03-01-2011
5 | The Doors of Stone | Rothfuss | NULL
6 | Beowulf | NULL | 01-01-1000
9. Điều này có thể được thực hiện với câu lệnh đơn giản này bằng cách sử dụng SELECT
primary_author,
published_date,
title
FROM
books
WHERE
[
primary_author IS NOT NULL
AND
published_date IS NOT NULL
];
7 với nhiều toán tử so sánhSELECT
primary_author,
published_date,
title
FROM
books
WHERE
[
primary_author IS NOT NULL
AND
published_date IS NOT NULL
];
Ghi chú. Dấu ngoặc đơn không bắt buộc nhưng nên đặt các bộ so sánh được nhóm lại để dễ đọc hơn
Ở đó bạn có nó;