Solved

T-SQL Using IN with a subquery

Posted on 2016-11-23
3
41 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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Hi all, It is important and often overlooked to understand “Database properties”. Often we see questions about "log files" or "where is the database" and one of the easiest ways to get general information about your database is to use “Database p…
Occasionally there is a need to clean table columns, especially if you have inherited legacy data. There are obviously many ways to accomplish that, including elaborate UPDATE queries with anywhere from one to numerous REPLACE functions (even within…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

821 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