I have the following tables
Product table:
id | product_type | product_code |
---|---|---|
200 | Camera | 3222333 |
201 | Television | 5432322 |
202 | PC | 4332233 |
203 | Mac | 1244532 |
204 | Notebook | 7543223 |
product_released_country1 table:
id | product_code | released_year |
---|---|---|
1 | 3222333 | 2000 |
2 | 3222333 | 2001 |
3 | 3222333 | 2003 |
4 | 5432322 | 2000 |
5 | 5432322 | 2001 |
6 | 5432322 | 2010 |
product_released_country2 table:
id | product_code | released_year |
---|---|---|
1 | 4332233 | 2000 |
2 | 4332233 | 2001 |
3 | 4332233 | 2009 |
4 | 1244532 | 2000 |
5 | 1244532 | 2001 |
6 | 1244532 | 2010 |
The products that gets released in different countries are saved in 2 different tables. I need a query that would return all products by checking both tables to see if any of the products have been released in 2010. If the product was released in 2010, then return 'yes' for the specific product. If the product hasn't been released in 2010 or haven't been released at all in any years (eg: product_code 7543223), then the query should return a 'no' for the is_product_released_in_2010 column.
Expected output:
id | product_type | product_code | is_product_released_in_2010 |
---|---|---|---|
200 | Camera | 3222333 | no |
201 | Television | 5432322 | yes |
202 | PC | 4332233 | no |
203 | Mac | 1244532 | yes |
204 | Notebook | 7543223 | no |
I tried joining both the tables using union all but still not getting the desired result. Any help would be greatly appreciated. Thank you.