0

I have enherited an Access-database with some queries. It is an account-database with information on the different accounts. Specifically IBAN-numbers for each account.

One of the queries is this, where we compare IBAN-numbers from the database with IBAN-numbers from the imported Id-table:

SELECT CAMTaccounts.IBAN, CAMTaccounts.Comment
FROM CAMTaccounts LEFT JOIN Id ON CAMTaccounts.[IBAN] = Id.[IBAN]
WHERE (((Id.IBAN) Is Null));

I thought I understood the SQL-language to some degree coming from SQL Server, but this statement, I cannot understand.

To me, this is equivalent to writing:

Select CAMTaccounts.*
From CAMTaccounts Left Outer Join Id On CAMTaccounts.IBAN = Id.IBAN
Where Id.IBAN Is Null

and this join, to me, does not make any sense.

But clearly, I am not understanding this correctly. I was hoping, that some of you could explain my flawed logic to me.

Thanks.

2
  • Why you think it doesnt make sense? Commented Apr 6, 2017 at 6:40
  • Because we join on = Id.IBAN and afterwards specify that Id.IBAN should be Null, which it never is and therefore the join is redundant. We only get data from the left table CAMTaccounts, but no data from the right Id-table. Commented Apr 6, 2017 at 6:49

2 Answers 2

2

This query will return all rows from CAMTaccounts which have no matching Id rows. This is known as Anti-join query. Excessive parenthesis really make no sense, most probably generated with a tool.

Sign up to request clarification or add additional context in comments.

1 Comment

Yes, I think it is generated with Query Designer in Access.
2

Suppose that CAMTaccounts.IBAN have values

A
B

And Id.IBAN have values

B
C

Then this query WITHOUT WHERE clause outputs something like this

`CAMTaccounts.IBAN` | `Id.IBAN`
 ---------------------------------
 A                  | NULL
 B                  | B

You can easily see what will result from this, if add Where Id.IBAN Is Null clause.

So, this query will give you result from CAMTaccounts table, when IBAN column doesn't contains value from Id.IBAN column

1 Comment

Thanks, both Oto and Serg for the answers.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.