Self Join

Overview

Find, inside a table, rows with values corresponds to a set of values, of a row within the table itself.

select tb.*
from some_table tb1
inner join some_table tb on tb.some_id = tb1.some_id and tb.some_field_value = tb1.some_field_value

inner join some_other_table otb on otb.some_other_field_value = tb.some_other_field_value
where tb1.some_other_field_value = :p_tb_id
and otb.something_else > 0

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License