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

  • Home
  • SEARCH
  • 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 8435005
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:48:50+00:00 2026-06-10T06:48:50+00:00

I have an issue with LINQ in vb.net. Basically I want create LEFT JOIN

  • 0

I have an issue with LINQ in vb.net. Basically I want create LEFT JOIN between two datatables.

This is the info of the two datatables:

Dim vDT1 As New DataTable
vDT1.Columns.Add("Key")
vDT1.Columns.Add("Data1")
vDT1.Columns.Add("Data2")

vDT1.Rows.Add({"01", "DATA1_AAAA", "DATA2_AAAA"})
vDT1.Rows.Add({"02", "DATA1_BBBB", "DATA2_BBBB"})

Dim vDT2 As New DataTable
vDT2.Columns.Add("Key")
vDT2.Columns.Add("Data3")
vDT2.Columns.Add("Data4")

vDT2.Rows.Add({"01", "DATA3_AAAA", "DATA4_AAAA"})
vDT2.Rows.Add({"01", "DATA3_BBBB", "DATA4_BBBB"})
vDT2.Rows.Add({"01", "DATA3_CCCC", "DATA4_CCCC"})
vDT2.Rows.Add({"01", "DATA3_DDDD", "DATA4_DDDD"})

Dim vDRnull As DataRow = vDTsec.Rows.Add

In order to achieve the LINQ JOIN I try to use the next sentence:

From a In vDT1.AsEnumerable
Group Join bTemp In vDT2.AsEnumerable
On a.Field(Of String)("Key") Equals bTemp.Field(Of String)("Key")
Into Group From b In Group.DefaultIfEmpty(vDRnull)
Select a, b

This is the result (but I want remove the red rows), I only want get the first occurrence in the second table:

Issue 1

Any help will be appreciated!


I edit the question with the correct method. Thanks to Jeff Mercado:

Dim vDT1 As New DataTable
vDT1.Columns.Add("Key")
vDT1.Columns.Add("Data1")
vDT1.Columns.Add("Data2")

vDT1.Rows.Add({"01", "DATA1_AAAA", "DATA2_AAAA"})
vDT1.Rows.Add({"02", "DATA1_BBBB", "DATA2_BBBB"})

Dim vDT2 As New DataTable
vDT2.Columns.Add("Key")
vDT2.Columns.Add("Data3")
vDT2.Columns.Add("Data4")

vDT2.Rows.Add({"01", "DATA3_AAAA", "DATA4_AAAA"})
vDT2.Rows.Add({"01", "DATA3_BBBB", "DATA4_BBBB"})
vDT2.Rows.Add({"01", "DATA3_CCCC", "DATA4_CCCC"})
vDT2.Rows.Add({"01", "DATA3_DDDD", "DATA4_DDDD"})

Dim vDRnull As DataRow = vDT2.Rows.Add

Dim vLINQ = From a In vDT1.AsEnumerable
    Group Join bTemp In vDT2.AsEnumerable
    On a.Field(Of Object)("Key") Equals bTemp.Field(Of Object)("Key")
    Into Group Let b = If(Group.FirstOrDefault Is Nothing, vDRnull, Group.FirstOrDefault)
    Select a, b

enter image description here

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

    The key is to call FirstOrDefault() on the group. Then you either have the first row in the group or Nothing.

    Dim query =
        From a In vDT1.AsEnumerable
        Group Join b In vDT2.AsEnumerable
            On a.Field(Of String)("Key") Equals b.Field(Of String)("Key")
            Into Group
        Let b = Group.FirstOrDefault
        Select Key = a.Field(Of String)("Key"),
               Data1 = a.Field(Of String)("Data1"),
               Data2 = a.Field(Of String)("Data2"),
               Data3 = b?.Field(Of String)("Data3"),
               Data4 = b?.Field(Of String)("Data4")
    
        ' Or Simply
        'Select a, b
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm having an issue getting a LINQ query to work. I have this XML:
I have an odd linq subquery issue. Given the following data structure: Parents Children
I'm currenlty using Asp.Net Dynamic Data, with Linq to Sql, to create an simple
I'm using .NET 4 and VS 2010 and have the same issue in .NET
I have an application using ASP.NET MVC, Unity, and Linq to SQL. The unity
I have an issue while trying to parse an Xml to Objects using Linq
In my .net application, I have used LINQ-to-SQL to get some data from the
I have a small issue binding the values into a dropdown using LINQ in
I have an existing database that I'm access with LINQ to Entity in .NET
I have an asp.net application developed. It uses LINQ to SQL to access database,

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.