I am looking for a way to join or get references from two separate tables based on certain conditions and am not sure if that is achievable or not.
Let me explain that in detail.
I have three tables, which are as follows.
- Brandnames
- RestrictedBrands
- Products
Now I am looking for a way to get the product data only for the brands that are listed in the “RestrictedBrands” table, but I want to add a condition that will consider the “Brandnames” table instead of “RestrictedBrands” table if the “RestrictedBrands” table is empty.
Please consider the following table structure as an example.
BrandNames table:
Brandid | Name |
---|---|
1 | Hp |
2 | IMB |
3 | Samsung |
Brandnames table:
Brandid | Name |
---|---|
3 | Cisco |
4 | Dell |
7 | Adobe |
Products table:
productid | brandid | productname |
---|---|---|
1 | hp | monitor |
2 | Dell | LCD |