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

Posted on 2014-12-15
Medium Priority
Last Modified: 2016-02-15
Is there a linq equivalent for "IN" operator in Select * FROM table where Id IN (Select Id FROM tableB)?
Question by:matthew phung
LVL 70

Expert Comment

by:Scott Pletcher
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
LVL 75

Accepted Solution

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


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


Featured Post

The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Sometimes MS breaks things just for fun... In Access 2003, only the maximum allowable SQL string length could cause problems as you built a recordset. Now, when using string data in a WHERE clause, the 'identifier' maximum is 128 characters. So, …
Article by: Tammy
MySQLTuner is a script written in Perl that allows you to review a MySQL installation quickly and make adjustments to increase performance and stability. The current configuration variables and status data is retrieved and presented in a brief forma…
This videos aims to give the viewer a basic demonstration of how a user can query current session information by using the SYS_CONTEXT function
Viewers will learn how the fundamental information of how to create a table.

600 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