Skip to Content
Feb 03, 2021 at 05:23 PM

Compare 2 fields value of the DB table with another 2 fields of different DB table in sub query.

67 Views Last edit Feb 03, 2021 at 05:26 PM 2 rev

Hi All,

I have a requirement as below.

Table 1 as fields -> Element ID, attribute ID, Text,

Table2 has fields -> Element ID, attribute ID, sequence number, value_for_element,

Now i need to select Element ID and attribute ID, Text fields value from table1 only if there is same element ID and attribute ID value in Table2.

So i wrote a sub/nested query like below which doesn't work.

Select Element ID attribute ID Text,

from table1 as A where ( A.element ID, A.attribute ID ) in ( select distinct Element ID, attribute ID from Table2 )

So basically , i want to compare 2 fields from outer query to inner query and fetch data from outer table.

Please suggest the possible ways to achieve this requirement.

Thanks in advance,