Try .NET /elinq/
Powered by Try .NET

SQL Server UNION

UNION and ORDER BY example

var query = DbContext.Set<FullName>()
                .Query((Staffs staffs, Customers customers, FullName alias) =>
                {
                    SELECT<FullName>(staffs.FirstName.@as(alias.FirstName), staffs.LastName.@as(alias.LastName));
                    FROM(staffs);

                    UNION_ALL();

                    var result = SELECT<FullName>(customers.FirstName.@as(alias.FirstName), customers.LastName.@as(alias.LastName));
                    FROM(customers);

                    return result;
                })
                .OrderBy(f => f.FirstName)
                .ThenBy(f => f.LastName);

foreach (var fullName in query.Take(3))
    Console.WriteLine((fullName.FirstName, fullName.LastName));

Replace UNION_ALL with UNION or INTERSECT or EXCEPT


< BACK | HOME