Solved

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

Posted on 2014-12-15
2
100 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: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
0
 
LVL 75

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

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Error when creating a table from a function 6 20
query linked sql table field from access 4 27
Amazon S3 .Net error 5 21
Why use this lambda? 12 40
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.

820 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