Skip to content
Advertisement

Replace subquery with join for the same table

Can the expected result in this case be accomplished without a subquery ? Maybe using a join ?

We have a name say ‘jose’, Expected result is all rows which has same color as jose. Query should run in both MS-SQL and ORACLE.

http://sqlfiddle.com/#!18/5f7e3/2

Advertisement

Answer

You can get this result with a JOIN, by self-joining on the color field, where the name in the second table is jose:

Output

SQL Server demo on SQLFIddle

Oracle demo on SQLFiddle

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