I am trying to get output which is in Table A no duplication. Flag will be Y when table B event ID will have to matched with (A,B,C) otherwise flag will be N.

Table A

| Id | Name | Flag |
| --- | --- | --- |
| 1 | Mike | Y |
| 2 | Bill | Y |

Table B

| ID | EventId |
| --- | --- |
| 1 | A |
| 1 | B |
| 1 | C |
| 1 | AAA |
| 1 | BBB |
| 2 | A |
| 2 | B |
| 2 | C |

Query:

```
SELECT 
    a.id, a.name 
FROM
    table a
LEFT OUTER JOIN
    (SELECT b.id, b.eventid 
     WHERE eventid IN ('A', 'B', 'C')) ah ON ah.id = b.id

```