Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

Posted on 2014-12-15
2
Medium Priority
?
130 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 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
0
 
LVL 75

Accepted Solution

by:
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.

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

NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

Question has a verified solution.

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

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
One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

916 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