Tincho Tincho - 1 month ago 7
SQL Question

SQL subquery to joins -

Is it possible to remove the subquery from this SQL?

Table has 2 attributes "id" and "field"
Many field could have the same Id.

These table has many registers with the same Id and different Value

In need get all same Id values using one of them like filter.

select *
from Table
where id = (select id from Table where value = 'someValue')


I think it could be really easy but I don't know how to do.

Answer

Self Join can be done

select T.Id,T.Field
from Table T
INNER JOIN  Table  TT
ON T.ID = TT.ID 
AND TT.Value = 'someValue'