> For the complete documentation index, see [llms.txt](https://jaywin.gitbook.io/leetcode/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://jaywin.gitbook.io/leetcode/solutions/1398-customers-who-bought-products-a-and-b-but-not-c.md).

# 1398. Customers Who Bought Products A and B but Not C

<https://leetcode.com/problems/customers-who-bought-products-a-and-b-but-not-c>

## Description

Table: `Customers`

```
+---------------------+---------+
| Column Name         | Type    |
+---------------------+---------+
| customer\_id         | int     |
| customer\_name       | varchar |
+---------------------+---------+
customer\_id is the primary key for this table.
customer\_name is the name of the customer.
```

Table: `Orders`

```
+---------------+---------+
| Column Name   | Type    |
+---------------+---------+
| order\_id      | int     |
| customer\_id   | int     |
| product\_name  | varchar |
+---------------+---------+
order\_id is the primary key for this table.
customer\_id is the id of the customer who bought the product "product\_name".
```

Write an SQL query to report the customer\_id and customer\_name of customers who bought products "A", "B" but did not buy the product "C" since we want to recommend them buy this product.

Return the result table **ordered** by customer\_id.

The query result format is in the following example.

```
Customers table:
+-------------+---------------+
| customer\_id | customer\_name |
+-------------+---------------+
| 1           | Daniel        |
| 2           | Diana         |
| 3           | Elizabeth     |
| 4           | Jhon          |
+-------------+---------------+
Orders table:
+------------+--------------+---------------+
| order\_id   | customer\_id  | product\_name  |
+------------+--------------+---------------+
| 10         |     1        |     A         |
| 20         |     1        |     B         |
| 30         |     1        |     D         |
| 40         |     1        |     C         |
| 50         |     2        |     A         |
| 60         |     3        |     A         |
| 70         |     3        |     B         |
| 80         |     3        |     D         |
| 90         |     4        |     C         |
+------------+--------------+---------------+
Result table:
+-------------+---------------+
| customer\_id | customer\_name |
+-------------+---------------+
| 3           | Elizabeth     |
+-------------+---------------+
Only the customer\_id with id 3 bought the product A and B but not the product C.
```

## ac

```java
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://jaywin.gitbook.io/leetcode/solutions/1398-customers-who-bought-products-a-and-b-but-not-c.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
