There is a trick, take this example:

```
table1(a, b, c). table2(a, b, d).
table1(e, [], f). table2(e, [], g).
table1(h, i, j). table2(h, i, k).
table1(l, [], m). table2(l, x, n).
table1(o, y, p). table2(o, [], q).
```

Now SQL wants me to compute:

```
SELECT Table1.Col1, Table1.Col2, Table1.Col3, Table2.Col4
FROM Table1 INNER JOIN Table2
ON Table1.Col1 = Table2.Col1
AND Table1.Col2 = Table2.Col2
Col1: Col2: Col3: Col4:
a b c d
h i j k
```

Prolog refuses somehow to do the right thing:

```
?- table1(X,Y,Z), table2(X,Y,T), write(X-Y-Z-T), nl, fail; true.
a-b-c-d
e-[]-f-g
h-i-j-k
true.
```

Well you can just try this, it is the Prolog equivalent to SQL join with NULL:

```
?- table1(X,Y,Z), table2(X,Y,T), Y\==[], write(X-Y-Z-T), nl, fail; true.
a-b-c-d
h-i-j-k
true.
```

This is because `[]=X`

and `X=[]`

anyway fail for `X`

an atom.

So you only need to filter `[]=[]`

.

You might also try dif/2:

```
?- dif(Y,[]), table1(X,Y,Z), table2(X,Y,T), write(X-Y-Z-T), nl, fail; true.
a-b-c-d
h-i-j-k
true.
```