0

I have two table, one is

ItemData(ItemID, ItemName)

and other one has few columns.

I can retrieve IDs from second table but I want ItemNames corresponding to those iIDs. I used following code but it is returning only one item name:

SELECT ItemName
  FROM ItemData
 WHERE ItemID = ( SELECT ItemID
                    FROM StoreItem
                   WHERE StoreId = 3
                     AND Value = 1)

2 Answers 2

1
SELECT ItemName from ItemData
WHERE ItemID in ( SELECT ItemID from StoreItem WHERE StoreId = 3 AND Value = 1)
Sign up to request clarification or add additional context in comments.

Comments

1

If your inner query returns more than 1 ItemID then use the IN clause -

SELECT ItemName from ItemData WHERE ItemID IN ( SELECT ItemID from StoreItem WHERE StoreId =3 AND Value=1)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.