---
title: SQL Exists
description: "## The SQL EXISTS Operator – SQL ОРШИХ Оператор The `EXISTS` operator is used to test for the existence of any record in a subquery. `EXISTS` оператортой дэд хүсэлт өгөхөд ямар нэгэн мэдээлэл байгаа эсэхийг шалгахад ашиглагддаг. The `EXISTS` operator returns TRUE if the…"
url: "https://apprentice.mn/docs/sql-exists/"
updated: "2024-07-21"
category: SQL
---

# SQL Exists

## The SQL EXISTS Operator – SQL ОРШИХ Оператор

The `EXISTS` operator is used to test for the existence of any record in a subquery.

`EXISTS` оператортой дэд хүсэлт өгөхөд ямар нэгэн мэдээлэл байгаа эсэхийг шалгахад ашиглагддаг.

The `EXISTS` operator returns TRUE if the subquery returns one or more records.

`EXISTS` оператортой дэд хүсэлт өгөхөд нэг буюу түүнээс дээш мэдээлэл буцаавал TRUE утга өгдөг.

### EXISTS Syntax – EXISTS Дүрэм

  `SELECT column_name(s)
FROM table_name
WHERE EXISTS
(SELECT column_name FROM table_name WHERE condition);`    `SELECT багана_нэр(нүүд)
FROM хүснэгт_нэр
WHERE EXISTS
(SELECT багана_нэр FROM хүснэгт_нэр WHERE нөхцөл);`  

## Demo Database – Жишээ мэдээллийн сан

Below is a selection from the “Products” table:

Доорх “Бүтээгдэхүүнүүд” хүснэгтийн хэсгийг жишээ болгож ашиглав:

| ProductID | ProductName | SupplierID | CategoryID | Unit | Price |
| --- | --- | --- | --- | --- | --- |
| 1 | Chais | 1 | 1 | 10 boxes x 20 bags | 18 |
| 2 | Chang | 1 | 1 | 24 – 12 oz bottles | 19 |
| 3 | Aniseed Syrup | 1 | 2 | 12 – 550 ml bottles | 10 |
| 4 | Chef Anton’s Cajun Seasoning | 2 | 2 | 48 – 6 oz jars | 22 |
| 5 | Chef Anton’s Gumbo Mix | 2 | 2 | 36 boxes | 21.35 |

And a selection from the “Suppliers” table:

Бас “Нийлүүлэгчид” хүснэгтийг хэсгийг:

| SupplierID | SupplierName | ContactName | Address | City | PostalCode | Country |
| --- | --- | --- | --- | --- | --- | --- |
| 1 | Exotic Liquid | Charlotte Cooper | 49 Gilbert St. | London | EC1 4SD | UK |
| 2 | New Orleans Cajun Delights | Shelley Burke | P.O. Box 78934 | New Orleans | 70117 | USA |
| 3 | Grandma Kelly’s Homestead | Regina Murphy | 707 Oxford Rd. | Ann Arbor | 48104 | USA |
| 4 | Tokyo Traders | Yoshi Nagase | 9-8 Sekimai Musashino-shi | Tokyo | 100 | Japan |

## SQL EXISTS Examples – SQL EXISTS жишээнүүд

The following SQL statement returns TRUE and lists the suppliers with a product price less than 20:

Доорх SQL өгүүлбэр нь TRUE утга өгч, 20-оос бага үнэтэй бүтээгдэхүүнтэй нийлүүлэгчдийг жагсаана:

### Example – Жишээ

> SELECT SupplierName
> FROM Suppliers
> WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price < 20);

 [Жишээ энд дарж харна уу.](https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_exists)     

The following SQL statement returns TRUE and lists the suppliers with a product price equal to 22:

Доорх SQL өгүүлбэр нь TRUE утга өгч, 22 үнэтэй бүтээгдэхүүнтэй нийлүүлэгчдийг жагсаана:

### Example – Жишээ

> SELECT SupplierName
> FROM Suppliers
> WHERE EXISTS (SELECT ProductName FROM Products WHERE Products.SupplierID = Suppliers.supplierID AND Price = 22);

 [Жишээ энд дарж харна уу.](https://www.w3schools.com/sql/trysql.asp?filename=trysql_select_exists2)         [https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists](https://www.addtoany.com/add_to/facebook?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists)[https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists](https://www.addtoany.com/add_to/mastodon?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists)[https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists](https://www.addtoany.com/add_to/email?linkurl=https%3A%2F%2Fapprentice.mn%2Fdocs%2Fsql-exists%2F&linkname=SQL%20Exists)[https://www.addtoany.com/share](https://www.addtoany.com/share)
