Skip to content
Advertisement

Changing In to Exists in SQL – with DISTINCT

Having this one:

Reading this one: Changing IN to EXISTS in SQL

Tried to change it into “Exists”, but produced this and it did not work:

The error is 3706: Syntax error: expected something between ‘=’ and ‘DISTINCT’ keyword.

Advertisement

Answer

You have already redundant code.
Inside the IN subquery you are selecting a column from ORGHEADER, so the LEFT join only adds noise since it returns in any case all rows from ORGHEADER.

Assuming that code belongs to a table aliased as t you can write the code with EXISTS like this:

Also, NOT IN will not work if the column parent of the table ORGRELATEDPARTY may return nulls.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement