Question: I have a table of orders. I want to obtain table 2 from table 1.

Table1:

| OrderID | ItemId |
| --- | --- |
| 1 | 1 |
| 1 | 2 |
| 2 | 3 |

Table2:

| OrderID | Items |
| --- | --- |
| 1 | [{"ItemId":1},{"ItemId":2}] |
| 2 | [{"ItemId":3}] |

How can I obtain table 2?

Answer: 
```
select 1 from blacklisted_usernames where 'AdminJohn' like name limit 1

```
If you need to check all existing names against the blacklisted patterns

```sql
SELECT usernames.name, 
       blacklisted_usernames.name blacklisted_pattern
FROM usernames
JOIN blacklisted_usernames 
    ON usernames.name LIKE blacklisted_usernames.name

```

Pay attention - this is complete tablescan, the indices won't be used, so the query will be slow.

You may need to check all existing names against newly added/altered patterns - in this case add according WHERE by `blacklisted_usernames` table (for example, by `created_at` or `updated_at` column).

If you need to check currently created username against all patterns then use [the solution](https://stackoverflow.com/a/72851977/10138734) provided by [ysth](https://stackoverflow.com/users/17389/ysth).