Hướng dẫn is not exist in mysql? - không tồn tại trong mysql?

13.2.11.6 & NBSP; Các nhóm phụ có tồn tại hoặc không tồn tại

Nếu một công cụ con trả về bất kỳ hàng nào, EXISTS subquery

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 và
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
1 là
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
2. Ví dụ:

SELECT column1 FROM t1 WHERE EXISTS [SELECT * FROM t2];

Theo truyền thống, một truy vấn con

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
3 bắt đầu với
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
4, nhưng nó có thể bắt đầu bằng
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
5 hoặc
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
6 hoặc bất cứ điều gì. MySQL bỏ qua danh sách
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
7 trong một truy vấn con như vậy, vì vậy nó không có gì khác biệt.

Đối với ví dụ trước, nếu

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
8 chứa bất kỳ hàng nào, thậm chí các hàng không có gì ngoài các giá trị
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
9, điều kiện
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
3 là
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0. Đây thực sự là một ví dụ không thể xảy ra bởi vì một truy vấn con
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
2 hầu như luôn luôn chứa các mối tương quan. Dưới đây là một số ví dụ thực tế hơn:

  • Những loại cửa hàng có mặt trong một hoặc nhiều thành phố?

    SELECT DISTINCT store_type FROM stores
      WHERE EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
  • Loại cửa hàng nào có mặt ở No City?

    SELECT DISTINCT store_type FROM stores
      WHERE NOT EXISTS [SELECT * FROM cities_stores
                        WHERE cities_stores.store_type = stores.store_type];
  • Những loại cửa hàng có mặt ở tất cả các thành phố?

    SELECT DISTINCT store_type FROM stores s1
      WHERE NOT EXISTS [
        SELECT * FROM cities WHERE NOT EXISTS [
          SELECT * FROM cities_stores
           WHERE cities_stores.city = cities.city
           AND cities_stores.store_type = stores.store_type]];

Ví dụ cuối cùng là truy vấn

SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
3 được lồng đôi. Đó là, nó có một mệnh đề
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
3 trong mệnh đề
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5. Chính thức, nó trả lời câu hỏi mà một thành phố có tồn tại với một cửa hàng không có trong
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
6 không? Nhưng dễ dàng hơn để nói rằng một
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5 được lồng vào câu hỏi là
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
8
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 cho tất cả
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
0?does a city exist with a store that is not in
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
6
? But it is easier to say that a nested
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5 answers the question is
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
8
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 for all
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
0?

Trong MySQL 8.0.19 và sau đó, bạn cũng có thể sử dụng

SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
3 hoặc
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5 với
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
3 trong truy vấn con, như thế này:

SELECT column1 FROM t1 WHERE EXISTS [TABLE t2];

Các kết quả giống như khi sử dụng

SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
4 mà không có mệnh đề
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
5 trong truy vấn con.


13.2.10.6 & NBSP; Các nhóm phụ có tồn tại hoặc không tồn tại

Nếu một công cụ con trả về bất kỳ hàng nào, EXISTS subquery

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 và
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
1 là
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
2. Ví dụ:

SELECT column1 FROM t1 WHERE EXISTS [SELECT * FROM t2];

Theo truyền thống, một truy vấn con

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
3 bắt đầu với
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
4, nhưng nó có thể bắt đầu bằng
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
5 hoặc
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
6 hoặc bất cứ điều gì. MySQL bỏ qua danh sách
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
7 trong một truy vấn con như vậy, vì vậy nó không có gì khác biệt.

Đối với ví dụ trước, nếu

SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
8 chứa bất kỳ hàng nào, thậm chí các hàng không có gì ngoài các giá trị
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
9, điều kiện
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
3 là
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0. Đây thực sự là một ví dụ không thể xảy ra bởi vì một truy vấn con
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
2 hầu như luôn luôn chứa các mối tương quan. Dưới đây là một số ví dụ thực tế hơn:

  • Những loại cửa hàng có mặt trong một hoặc nhiều thành phố?

    SELECT DISTINCT store_type FROM stores
      WHERE EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
  • Loại cửa hàng nào có mặt ở No City?

    SELECT DISTINCT store_type FROM stores
      WHERE NOT EXISTS [SELECT * FROM cities_stores
                        WHERE cities_stores.store_type = stores.store_type];
  • Những loại cửa hàng có mặt ở tất cả các thành phố?

    SELECT DISTINCT store_type FROM stores s1
      WHERE NOT EXISTS [
        SELECT * FROM cities WHERE NOT EXISTS [
          SELECT * FROM cities_stores
           WHERE cities_stores.city = cities.city
           AND cities_stores.store_type = stores.store_type]];

Ví dụ cuối cùng là truy vấn

SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
3 được lồng đôi. Đó là, nó có một mệnh đề
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
3 trong mệnh đề
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5. Chính thức, nó trả lời câu hỏi mà một thành phố có tồn tại với một cửa hàng không có trong
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
6 không? Nhưng dễ dàng hơn để nói rằng một
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5 được lồng vào câu hỏi là
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
8
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 cho tất cả
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
0?does a city exist with a store that is not in
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
6
? But it is easier to say that a nested
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
5 answers the question is
SELECT DISTINCT store_type FROM stores
  WHERE NOT EXISTS [SELECT * FROM cities_stores
                    WHERE cities_stores.store_type = stores.store_type];
8
SELECT DISTINCT store_type FROM stores
  WHERE EXISTS [SELECT * FROM cities_stores
                WHERE cities_stores.store_type = stores.store_type];
0 for all
SELECT DISTINCT store_type FROM stores s1
  WHERE NOT EXISTS [
    SELECT * FROM cities WHERE NOT EXISTS [
      SELECT * FROM cities_stores
       WHERE cities_stores.city = cities.city
       AND cities_stores.store_type = stores.store_type]];
0?


Những gì không tồn tại trong MySQL?

Trong MySQL 8.0. 19 và sau đó, bạn cũng có thể sử dụng không tồn tại hoặc không tồn tại với bảng trong truy vấn con, như thế này: chọn cột1 từ T1 nơi tồn tại [Bảng T2]; Các kết quả giống như khi sử dụng Select * không có mệnh đề WHERE trong SBURERY.use NOT EXISTS or NOT EXISTS with TABLE in the subquery, like this: SELECT column1 FROM t1 WHERE EXISTS [TABLE t2]; The results are the same as when using SELECT * with no WHERE clause in the subquery.

Không tồn tại trong SQL?

Nhà điều hành SQL không tồn tại sẽ hoạt động hoàn toàn đối diện với toán tử tồn tại.Nó rất hữu ích trong việc hạn chế số lượng hàng được trả về bởi câu lệnh select.Không tồn tại trong SQL Server sẽ kiểm tra trình điều khiển con cho sự tồn tại của hàng.Nếu không có hàng thì nó sẽ trả về đúng, nếu không thì sai.If there are no rows then it will return TRUE, otherwise FALSE.

Là truy vấn tồn tại trong mysql?

MySQL tồn tại toán tử tồn tại Nhà điều hành tồn tại được sử dụng để kiểm tra sự tồn tại của bất kỳ bản ghi nào trong một truy vấn con.Nhà điều hành tồn tại trả về true nếu trình điều khiển con trả về một hoặc nhiều bản ghi.The EXISTS operator is used to test for the existence of any record in a subquery. The EXISTS operator returns TRUE if the subquery returns one or more records.

Không tồn tại trong cơ sở dữ liệu?

SQL không tồn tại trong một trình điều khiển phụ bằng các từ đơn giản, trình điều khiển con không tồn tại kiểm tra từng hàng từ truy vấn bên ngoài, trả về đúng hoặc sai, sau đó gửi giá trị đến truy vấn bên ngoài để sử dụng.Nói một cách đơn giản hơn, khi bạn sử dụng SQL không tồn tại, truy vấn trả về tất cả các hàng không thỏa mãn điều kiện tồn tại.the query returns all the rows that don't satisfy the EXISTS condition.

Bài Viết Liên Quan

Chủ Đề