for the table below, how can I write a subquery for my select query so that I can return a flag column when the Inv = Esc for a given Num ?
In the example below, the second row is a match as well as the fifth row. Tried but keep getting boggled. Thanks.
**Additionally, there should be only one Flag for each Num.
Num | Name |Inv |Esc|Flag
1) *785* | AB7851 |155 |496
2) *785* | AB7852 |**496 |496** |**Hit**
3) *785* | AB7853 |518 |496
4) *785* | AB7854 |769 |496
5) 236 | AB785Q |**155 |155** |**Hit**
6) 236 | AB785R |496 |155
7) 236 | AB785S |518 |155
8) 236 | AB785T |747 |155
9) 236 | AB785U |769 |155
select *, case when inv = esc then 1 else 0 end as flag from my_table;