> For the complete documentation index, see [llms.txt](https://anton-veselskyi.gitbook.io/codding-problems-solutions/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://anton-veselskyi.gitbook.io/codding-problems-solutions/codewars/6-kyu/sql-basics-simple-exists.md).

# SQL Basics: Simple EXISTS

## [SQL Basics: Simple EXISTS](https://www.codewars.com/kata/58113a64e10b53ec36000293)

For this challenge you need to create a SELECT statement that will contain data about departments that had a sale with a price over 98.00 dollars. This SELECT statement will have to use an EXISTS to achieve the task.

### departments table schema

* id
* name

### sales table schema

* id
* department\_id (department foreign key)
* name
* price
* card\_name
* card\_number
* transaction\_date

### resultant table schema

* id
* name

> NOTE: Your solution should use pure SQL. Ruby is used within the test cases to do the actual testing. Do not: alias tables as this can cause a failure.

## Solutions

#### 🗃️ Sql

```sql
select id, name
from departments
where exists(select name from sales where departments.id = sales.department_id and price > 98);
```
