Hello All,

I am facing a problem coming up with a SQL query for a certain issue:

Table 1
-------------------
Client ID|Name of Client|Customer Type|Account Type|
01| A |    AB        |      30      |
02| B |    AB        |      30      |
03| C |    CD        |      30      |
04| D |    CF        |      40      |


Table 2
-----------------
Argument|Switch|
AB30     |  Y  |
CD30     |  N  |
CF40     |  Y  |

Table 3
-------------------
ClientID|Name Of Client|External_Information|
01|A    | External A
02|B    | External B
03|C    | External C

Currently, I am trying to extract the information based on 3 different tables. I am suppose to extract the External Information from Table 3 based on 3 conditions

1) The Client ID must exist in Table 3 and Table 1
2) If the Client ID exist in Table 3 and Table 1, then we must check in Table 2 if the combination of Customer Type and Account Type (eg : For Client ID 01 , the combination would be AB30)
in Table 1 exist in Table 2 and if the Switch in Table 2 = "Y".

My current SQL would be :

select External_Information from Table_3 a where a.ClientID = (select ClientID from Table_1 where ClientID = a.ClientID);

This would solve Condition 1 , but for condition 2 I am not sure how we are able to do it within the same SQL query.

The expected result should be :

External_Information

External A
External B

I managed to solve the issue using the CONCAT statement.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.