Subquery with multiple results, SQL Server
sql, sql-server, t-sql
Solution
Use `IN` instead of `=` for result sets:
SELECT *
FROM dbo.document_library_file_attributes
WHERE my_file_id IN
(SELECT my_file_id
FROM dbo.document_library_file_attributes
WHERE attribute_name='Directory/Key' AND attribute_value LIKE @directory+'%')
It:
Determines whether a specified value matches any value in a subquery or a list.
Problem
I have a query that looks like this: ``` SELECT * FROM dbo.document_library_file_attributes WHERE my_file_id= (SELECT my_file_id FROM dbo.document_library_file_attributes WHERE attribute_name='Directory/Key' AND attribute_value LIKE @directory+'%') ``` I want to the subquery to be able to return multiple results, meaning `my_file_id` could equal 'directoryA', 'directoryB', and I want the results for all of these. How would I do that?