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 9124425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T06:34:09+00:00 2026-06-17T06:34:09+00:00

I have two result sets from database into object and when I inner join

  • 0

I have two result sets from database into object and when I inner join them, it returns cross join. Following is my code:

var nw = new NorthwindEntities();
var employee1 = (from emp in nw.Employees
                 join ord in nw.Orders on emp.EmployeeID equals ord.EmployeeID
                 where emp.EmployeeID == 5
                 select new
                 {
                     empID = emp.EmployeeID,
                     empName = emp.FirstName,
                     ordDate = ord.OrderDate
                 }).ToList();

var employee2 = (from emp in nw.Employees
                 join ord in nw.Orders on emp.EmployeeID equals ord.EmployeeID
                 where emp.EmployeeID == 5
                 select new
                 {
                     empID = emp.EmployeeID,
                     empName = emp.FirstName,
                     shpAddress = ord.ShipAddress
                 }).ToList();

var employee = from e1 in employee1
               join e2 in employee2 on new { e1.empID } equals new { e2.empID }
               select new
               {
                   empID = e1.empID,
                   empName = e1.empName,
                   ordDate = e1.ordDate,
                   orAdd = e2.shpAddress
               };

gvAll.DataSource = employee.ToList();

Now when I join employee1 and employee2 into employee, I get a cross join of those data set. Any help would be highly appreciated.

My main target behind this is to have data returned from database stored in some place temporarily so I can work it with later with other data retrieved from database.

employee1 and employee2 uses same query for employee id (5) except employee1 has empID, empName and OrderDate where as employee2 has empID, empName and shipAddress. Now I want empID, empName, OrderDate and ShipAddress out of employee1 and employee2 in employee. empID is common in both but I am getting a cross join. Thank you.

  • 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-06-17T06:34:10+00:00Added an answer on June 17, 2026 at 6:34 am

    In employee1 and employee2 you will aslo need the OrderId column to and then join them by both cos you need to get an equal unique key on both tables.

    and from what you wrote I think that empID is not unique in either tables cos you can have more orders for same empID

    So first you need a unique key on both employee1 and employee2 then you can join on that.

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

Sidebar

Related Questions

I have two following rows of code: Microsoft.VisualBasic.Interaction.Beep() or Microsoft.VisualBasic.Beep() The result is the
I have two iterators which i have to merge into one result. Here are
I have to fetch 500K rows from the database and write that data into
I have this managed bean which takes two values from database's table import java.io.Serializable;
I'm building a cross-database view that consolidates data from two different subsystems for reporting.
I have an HTML page and I want to fetch the result between two
I have to make a conditional in ash, that depends on result of two
I have two results from a data set. I want to add both results
I have two tables that I join on the id-column, they look like: +-------+
I have a SQL database with two tables like this: Users Id (PK) Name

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.