Обратите внимание, что вы также разместили свой вопрос здесь. Ваш вопрос все еще не решен? Вы можете попробовать мой код следующим образом. Извините, я не использовал SQL, я использовал класс, но это не повлияло на результат.
Public Class Form1
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
Dim MK100 As NewPerson = New NewPerson With {
.MK = "100",
.First_Name = "Mike",
.Last_Name = "Smith",
.Team = "A"
}
Dim MK101 As NewPerson = New NewPerson With {
.MK = "101",
.First_Name = "Dave",
.Last_Name = "Sharp",
.Team = "A"
}
Dim MK102 As NewPerson = New NewPerson With {
.MK = "102",
.First_Name = "Roger",
.Last_Name = "Hands",
.Team = "A"
}
Dim MK103 As NewPerson = New NewPerson With {
.MK = "103",
.First_Name = "Keely",
.Last_Name = "Riller",
.Team = "A"
}
Dim MK104 As NewPerson = New NewPerson With {
.MK = "104",
.First_Name = "Simon",
.Last_Name = "Says",
.Team = "A"
}
Dim MK105 As NewPerson = New NewPerson With {
.MK = "105",
.First_Name = "Eugene",
.Last_Name = "Phillips",
.Team = "A"
}
Dim MK106 As NewPerson = New NewPerson With {
.MK = "106",
.First_Name = "William",
.Last_Name = "Nobody",
.Team = "B"
}
Dim FK101 As NewDate = New NewDate With {
.FK = "101",
.Date_ = "15-Mar-20",
.Allocated = "Job Number 1"
}
Dim FK102 As NewDate = New NewDate With {
.FK = "102",
.Date_ = "15-Mar-20",
.Allocated = "Vacation"
}
Dim FK103 As NewDate = New NewDate With {
.FK = "103",
.Date_ = "15-Mar-20",
.Allocated = "Sick"
}
Dim FK104 As NewDate = New NewDate With {
.FK = "104",
.Date_ = "15-Mar-20",
.Allocated = "Job nunber 2"
}
Dim Person_Data_table As List(Of NewPerson) = New List(Of NewPerson) From {
MK100,
MK101,
MK102,
MK103,
MK104,
MK105,
MK106
}
Dim Date_Table As List(Of NewDate) = New List(Of NewDate) From {
FK101,
FK102,
FK103,
FK104
}
Dim query = From NewPerson In Person_Data_table Group Join NewDate In Date_Table On NewPerson.MK Equals NewDate.FK Into gj = Group From subperson In gj.DefaultIfEmpty() Where (NewPerson.Team = "A") AndAlso (subperson Is Nothing OrElse ((subperson.Allocated <> "Vacation") AndAlso (subperson.Allocated <> "Sick"))) Select New With {NewPerson.MK, NewPerson.First_Name, NewPerson.Last_Name, NewPerson.Team
}
For Each v In query
ListBox1.Items.Add($"{v.MK,-15}{v.First_Name,-15}{v.Last_Name,-15}{v.Team}")
Next
End Sub
End Class
Class NewPerson
Public Property MK As String
Public Property First_Name As String
Public Property Last_Name As String
Public Property Team As String
End Class
Class NewDate
Public Property FK As String
Public Property Date_ As String
Public Property Allocated As String
End Class
И эффект следующий: