Solved

linq equivalent for "IN" operator in Select * FROM table where Id IN (Select Id FROM tableB)

Posted on 2014-12-15
2
93 Views
Last Modified: 2016-02-15
Is there a linq equivalent for "IN" operator in Select * FROM table where Id IN (Select Id FROM tableB)?
0
Comment
Question by:matthew phung
2 Comments
 
LVL 69

Expert Comment

by:ScottPletcher
ID: 40501570
That's (almost) equal to an INNER JOIN, so maybe:

 Select distinct t.* FROM table t inner join tableb b where t.id = b.id
0
 
LVL 74

Accepted Solution

by:
käµfm³d   👽 earned 500 total points
ID: 40501593
If I recall correctly, you can use the Contains extension method. It should get converted to the appropriate SQL syntax.

e.g.

var inner = from Id in tableB
            select Id;

var outer = from t in table
            where inner.Contains(t.Id)
            select t;

Open in new window

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
Composite queries are used to retrieve the results from joining multiple queries after applying any filters. UNION, INTERSECT, MINUS, and UNION ALL are some of the operators used to get certain desired results.​
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

708 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now