Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 907997
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:38:39+00:00 2026-05-15T16:38:39+00:00

I need the fields in 1 table contingent on 1 property matching rows in

  • 0

I need the fields in 1 table contingent on 1 property matching rows in another table.
I can write this query in SQL with a subquery as such:

SELECT *
FROM Table1
WHERE Property1 IN
(
    SELECT Property1
    FROM Table2
    WHERE Property0 = 1
)

But I read here that it’s less complicated and just as easy to write with a join, which I did. However, so far I’m unable to return just Table1 as I’d like since I’m using a join, which if I’m not mistaken, requires me to create this anonymous type, as below. What I did here works (I created another object with the same properties of Table1 I need), but I can’t help thinking there’s a better way to do this.

Table1.Join(Table2, t1 => t1.Property1, t2 => t2.Property1, (t1, t2) => new
{
    t1.Property1,
    t1.Property2,
    t1.Property3
})
.Select(ob => new UnnecessaryObject
{
    Property1 = ob.Property1,
    Property2 = ob.Property2,
    Property3 = ob.Property3
}

I also tried just creating a Table1 in the .Select part, but I got an error about explicit construction not being allowed.

Just to clarify, I’d like to be able to return the IQueryable of type Table1, which it seems like I ought to be able to do without having to create UnnecessaryObject…but I’m still pretty new to LINQ, so I’d appreciate any help you can offer. Thanks in advance.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T16:38:40+00:00Added an answer on May 15, 2026 at 4:38 pm

    You could just do:

    from t1 in table1
    join t2 in table2 on t1.property1 equals t2.property1
    select t1;
    

    That would return a collection of table1 objects. This assumes from your example table1 is a collection of table1 objects and table2 is a collection of table2 objects.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This script here by GeekFish can get you empty/null fields in a table. It
I need to iterate through the fields on a table and do something if
I need to index a varchar field on my table in MS SQL Server
when I need the columns of an existing table I use the query: SELECT
I need to get summary data from many many rows. The summary fields are
I am trying to write a SQL query where I am joining two tables
I have a need to monitor a subset of fields on a table and
I have this MySQL query. I have database fields with this contents sports,shopping,pool,pc,games shopping,pool,pc,games
I need to update the comments field in a table for a large list
I need a simple table with a user name and password field in MySQL.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.