I have a multi-table SELECT query which compares column values with itself like below:
SELECT * FROM table1 t1,table2 t2
WHERE t1.col1=t2.col1 --Different tables,So OK.
AND t1.col1=t1.col1 --Same tables??
AND t2.col1=t2.col1 --Same tables??
This seems redundant to me.
My query is, Will removing them have any impact on logic/performance?
Thanks in advance.
This seems redundant, its only effect is removing lines that have NULL values in these columns. Make sure the columns are NOT NULL before removing those clauses.If the columns are nullable you can safely replace these lines with (easier to read, easier to maintain):
Update following Jeffrey’s comment
You’re absolutely right, I don’t know how I didn’t see it myself: the join condition
t1.col1=t2.col1implies that only the rows with the join columns not null will be considered. The clausestx.col1=tx.col1are therefore completely redundant and can be safely removed.