I have many SQL queries, such as:
SELECT o.Id, o.attrib1, o.attrib2
FROM table1 o
WHERE o.Id IN (
SELECT DISTINCT Id
FROM table1
, table2
, table3
WHERE ...
)
These queries must be run on different database systems (MySql, Oracle, DB2, MS-Sql, Hypersonic), so I can only use regular SQL syntax.
Here I read that with MySql the statement is INnot optimized and it is very slow, so I want to switch this to JOIN.
I tried:
SELECT o.Id, o.attrib1, o.attrib2
FROM table1 o, table2, table3
WHERE ...
But this does not account for the keyword DISTINCT.
Question: How to get rid of duplicate lines using an approach JOIN?
source
share