Question: I have been trying to develop a query to solve a problem but its been hard.

Table 1:

```
+------+----+
| NAME | ID |
+------+----+
| A    |  1 |
| A    |  2 |
| B    |  1 |
| B    |  5 |
| C    |  8 |
+------+----+

```

Table 2:

```
+------+----+
| NAME | ID |
+------+----+
| A    |  1 |
| A    |  4 |
| B    |  3 |
| B    |  5 |
| D    |  9 |
+------+----+

```

From these results, I need to return everything from table 2 that the name contains in table 1 and the ID don't.

So, this example, the return should be:

```
+------+----+
| NAME | ID |
+------+----+
| A    |  4 |
| B    |  3 |
+------+----+

```

Answer: 
I would do:

```
with t1 as (select 'A' name, 1 id from dual union all
            select 'A' name, 2 id from dual union all
            select 'B' name, 1 id from dual union all
            select 'B' name, 5 id from dual union all
            select 'C' name, 8 id from dual),
     t2 as (select 'A' name, 1 id from dual union all
            select 'A' name, 4 id from dual union all
            select 'B' name, 3 id from dual union all
            select 'B' name, 5 id from dual union all
            select 'D' name, 9 id from dual)
select name, id
from   t2
where  name in (select name from t1)
minus
select name, id
from   t1;

NAME         ID
---- ----------
A             4
B             3

```
You can use a NOT EXISTS or similar:

```
SELECT  t2.*
FROM Table2 t2
WHERE NOT EXISTS
(
   SELECT 1
   FROM Tabl1 t1
   WHERE t1.Name = t2.Name
   AND t1.Id = t2.Id
);

```