Skip to content
This repository was archived by the owner on Oct 26, 2023. It is now read-only.

2 Advanced select statement with FluentQueryBuilder

Gustavo Fontes edited this page Oct 14, 2017 · 1 revision

There are a lot of select statement features that you can to compose your query with flepper. Here, We will to show to you how you can do select with inner join, left join, how you can use sql functions like Max, Min, Count and how you can use alias table at the columns and alias to columns.

Creating select statement with Joins

To create the statement with flepper, use the namespace Flepper.QueryBuilder.FlepperQueryBuilder

ex:

    FlepperQueryBuilder
    .Select(
        "Name",
        "Age",
        "PostalCode")
    .From("User").As("usr")
    .InnerJoin("Address").As("adr")
    .On("usr","AddressId").EqualTo("adr","Id")
    .Build();

The code above generate the query:

SELECT 
    Name,
    Age,
    PostalCode
FROM [User] AS usr 
INNER JOIN [Address] AS adr 
ON [usr].AddressId = [adr].Id

The code to do LEFT JOIN is not much diferent than INNER JOIN. See below an example:

    FlepperQueryBuilder
    .Select(
        "Name",
        "Age",
        "PostalCode")
    .From("User").As("usr")
    .LeftJoin("Address").As("adr")
    .On("usr","AddressId").EqualTo("adr","Id")
    .Build();

And the result:

SELECT 
    Name,
    Age,
    PostalCode
FROM [User] AS usr 
LEFT JOIN [Address] AS adr 
ON [usr].AddressId = [adr].Id

Creating select statement with column alias

To alias in columns and sql functions, like MIN and Count, you need use the namespace Flepper.QueryBuilder.FlepperQueryFunction;.

ex:

  .Select(
        As("Name","FirstName"),
        "Age")
    .From("User")

The code above generate the query:

SELECT 
    Name As FirsName,
    Age,
    PostalCode
FROM [User]
Clone this wiki locally