0

I have table of shops name, ID, Type,etc. Also I have classes of shops (supermarkets, store, retailer) and each class has several types (supermarket = megamarket, multimarket, etc) I would like to get all shops which are supermarkets. Let's assume supermarkets is ShopClass 2.

So I would like to write query like this:

SELECT ShopID, ShopName 
FROM Shops 
WHERE ShopType in (SELECT ShopType FROM ShopClasses WHERE ShopClass = 2) 

But unfortunately that query doesn't work:

Only one expression can be specified in the select list when the subquery is not introduced with EXISTS

What is the reason? AFAIK I can use expressions in IN statement.

1 Answer 1

1

Try this:

SELECT ShopID, ShopName 
FROM Shops AS shopslist 
WHERE shopslist.ShopType in (SELECT ShopType FROM ShopClasses WHERE ShopClass = 2)
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks, it works now. Quite strange, but that is the exact solution.
If you post code, XML or data samples, PLEASE highlight those lines in the text editor and click on the "code samples" button ( { } ) on the editor toolbar to nicely format and syntax highlight it!

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.