Hi all,
Thank you in advance for your time and suggestions.
I am new to SQL and trying to extract rows from table A join Table B on lid such that
for each group of gid having same sid but different ad_name (result look like Table C).
Table A
id | name | gid | lid |
---|---|---|---|
1 | name_abc | G11 | 11 |
2 | name_def | G12 | 12 |
3 | name_ghi | G13 | 13 |
4 | name_abc | G14 | 14 |
5 | name_ghf | G15 | 15 |
5 | name_ghf | G15 | 16 |
Table B
lid | ad_name | sid |
---|---|---|
11 | add_abc | 111 |
11 | add_abc | 111 |
11 | add_cde | 111 |
14 | add_abc | 155 |
11 | add_abc | 155 |
14 | add_cde | 155 |
12 | add_dce | 123 |
12 | add_dce | 123 |
13 | add_jhg | 126 |
13 | add_khg | 127 |
15 | add_kih | 131 |
16 | add_kik | 131 |
Table C
id | name | gid | lid | sid | ad_name |
---|---|---|---|---|---|
1 | name_abc | G11 | 11 | 111 | add_abc |
1 | name_abc | G11 | 11 | 111 | add_cde |
1 | name_abc | G11 | 11 | 111 | add_abc |
4 | name_abc | G14 | 14 | 155 | add_abc |
4 | name_abc | G14 | 14 | 155 | add_cde |
5 | name_ghf | G15 | 15 | 131 | add_kih |
5 | name_ghf | G15 | 16 | 131 | add_kik |