0

I am working on writing a SQL query to get data from 2 tables with inner join and need some help. Here is the scenario. I have 2 tables say A and B.

table A

Name Value
1 Red
2 Green
3 Blue
4 Yellow
5 White

Table B

Name Value
Shirt 1,3
Shoe 1,2,4
Sock 4,5

Now, I am trying to write a query to join these 2 tables so that when I want to get data for shirt, I would retrieve Red and Blue.

I have tried the below but it is not taking the values to be list for the IN Clause.

Test-1

SELECT Value FROM A WHERE Name IN

(
SELECT Value FROM B WHERE Name = 'Shirt'
)

Test-2

SELECT Value FROM A INNER JOIN B ON
A.Name IN B.Value
WHERE B.Name = 'Shirt'

Test-3

SELECT Value FROM A WHERE Name IN

(
SELECT CAST(Value AS VARCHAR(50)) FROM B WHERE Name = 'Shirt'
)

We are using DB2 v9.5 database and will be making an ODBC connection from our application to retrieve data.

Any suggestion would be greatly appreciated

1

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.