> For the complete documentation index, see [llms.txt](https://docs.dot-net.uz/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.dot-net.uz/c-.net/linq/join-operatorlari/left-join.md).

# Left Join

Avvalgi **JOIN** tularidan farqli tomoni **LEFT JOIN** da maydon bo’sh bo’lishi ham mumkin. Ikki ro’yhatni birlashtirish vaqtida agar to’g’ri keladigan maydon topilmasa uni bo’sh holatda (null) tashlab ketadi. Buning uchun **DefaultEmpty** metodidan foydalanamiz:

Query Syntax:

```csharp
class Program
{
    static void Main(string[] args)
    {
        var students = new List<Student>()
    {
        new Student() { Id = 1, Name = "Jasurbek", AddressId = 1},
        new Student() { Id = 2, Name = "Xondamir", AddressId = 5},
        new Student() { Id = 3, Name = "Shoxruh", AddressId = 3},
        new Student() { Id = 4, Name = "Shaxzod", AddressId = 4},
        new Student() { Id = 5, Name = "Abdulloh"}
    };
        var addresses = new List<Address>()
    {
        new Address() {Id = 1, AddressLine = "Line 1"},
        new Address() {Id = 2, AddressLine = "Line 2"},
        new Address() {Id = 3, AddressLine = "Line 3"},
        new Address() {Id = 4, AddressLine = "Line 4"},
    };
        var QueerySyntax = from std in students
                            join add in addresses on
                            std.AddressId equals add.Id into
                            stdAddress
                            from studentAddress in stdAddress.DefaultIfEmpty()
                            select new { Name = std.Name, StudentAddress = studentAddress != null ? studentAddress.AddressLine : "Empty"};
        foreach (var item in QueerySyntax)
        {

            Console.WriteLine($"Name: {item.Name} Line: {item.StudentAddress}");
        }
        /*OUTPUT:   Name: Jasurbek Line: Line 1
                    Name: Xondamir Line: Empty
                    Name: Shoxruh Line: Line 3
                    Name: Shaxzod Line: Line 4
                    Name: Abdulloh Line: Empty  */
    }
}
class Student
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int AddressId { get; set; }
}
class Address
{
    public int Id { get; set; }
    public string AddressLine { get; set; }
}
```

Method Syntax:

```csharp
class Program
{
    static void Main(string[] args)
    {
        var students = new List<Student>()
    {
        new Student() { Id = 1, Name = "Jasurbek", AddressId = 1},
        new Student() { Id = 2, Name = "Xondamir", AddressId = 5},
        new Student() { Id = 3, Name = "Shoxruh", AddressId = 3},
        new Student() { Id = 4, Name = "Shaxzod", AddressId = 4},
        new Student() { Id = 5, Name = "Abdulloh"}
    };
        var addresses = new List<Address>()
    {
        new Address() {Id = 1, AddressLine = "Line 1"},
        new Address() {Id = 2, AddressLine = "Line 2"},
        new Address() {Id = 3, AddressLine = "Line 3"},
        new Address() {Id = 4, AddressLine = "Line 4"},
    };
            var MethodSyntax = students.GroupJoin(addresses, std => std.AddressId, add => add.Id,
                (std, add) => new { std, add }).SelectMany(x => x.add.DefaultIfEmpty(), 
                (StudentData, AddressData) => new { Name = StudentData.std.Name, Line = AddressData != null ? AddressData.AddressLine : "Empty"});
        foreach (var item in MethodSyntax)
        {

            Console.WriteLine($"Name: {item.Name} Line: {item.Line}");
        }
        /*OUTPUT:   Name: Jasurbek Line: Line 1
                    Name: Xondamir Line: Empty
                    Name: Shoxruh Line: Line 3
                    Name: Shaxzod Line: Line 4
                    Name: Abdulloh Line: Empty  */
    }
}
class Student
{
    public int Id { get; set; }
    public string Name { get; set; }
    public int AddressId { get; set; }
}
class Address
{
    public int Id { get; set; }
    public string AddressLine { get; set; }
}
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.dot-net.uz/c-.net/linq/join-operatorlari/left-join.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
