Solved

T-SQL Using IN with a subquery

Posted on 2016-11-23
3
34 Views
Last Modified: 2016-11-23
Using IN with a subquery
https://msdn.microsoft.com/en-us/library/ms177682.aspx

I'm using the IN from the above link

I'm using sql server Northwind database

When I run this query

-- Determines whether a specified value matches any value in a subquery or a list.
SELECT * FROM [Northwind].[dbo].[Orders]
WHERE [CustomerID] IN(
                      SELECT * FROM [Northwind].[dbo].[Customers]                            
                     )


I get this error

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

Any idea of why i'm getting this error
0
Comment
Question by:maqskywalker
3 Comments
 
LVL 34

Accepted Solution

by:
Brian Crowe earned 250 total points
ID: 41899553
You need to specify what column you are looking for CustomerID in instead of using SELECT *
1
 
LVL 12

Assisted Solution

by:Jeff Darling
Jeff Darling earned 250 total points
ID: 41899649
like this

SELECT * FROM [Northwind].[dbo].[Orders]
WHERE [CustomerID] IN(
                      SELECT CustomerID FROM [Northwind].[dbo].[Customers]                             
                     )

Open in new window

0
 
LVL 1

Author Closing Comment

by:maqskywalker
ID: 41899680
thanks
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
SQL Server Question 5 36
Ssis not sending failure message 2 25
This query failed in sql 2014 5 29
SQL Improvement  ( Speed) 14 26
After restoring a Microsoft SQL Server database (.bak) from backup or attaching .mdf file, you may run into "Error '15023' User or role already exists in the current database" when you use the "User Mapping" SQL Management Studio functionality to al…
There have been several questions about Large Transaction Log Files in SQL Server 2008, and how to get rid of them when disk space has become critical. This article will explain how to disable full recovery and implement simple recovery that carries…
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question