SqlKata - Dynamic Sql query builder for dotnet | Product Hunt

🎉 SqlKata is now on Product Hunt

Please upvote to support the product development

Combining Multiple Queries

Union / Except / Intersect

SqlKata allows you to combine multiple queries using one of the following available operators union, intersect and except by providing the following methods Union, UnionAll, Intersect, IntersectAll, Except and ExceptAll.

the above methods accept either an instance of Query or a labmda expression

//:playground
var phones = new Query("Phones");
var laptops = new Query("Laptops");

var mobiles = laptops.Union(phones);
(SELECT * FROM [Laptops]) UNION (SELECT * FROM [Phones])

Or by using the labmda overload

//:playground
var mobiles = new Query("Laptops").ExceptAll(q => q.From("OldLaptops"));
(SELECT * FROM [Laptops]) EXCEPT ALL (SELECT * FROM [OldLaptops])

Combining Raw Expressions

You can always use the CombineRaw method to append raw expressions

//:playground
var mobiles = new Query("Laptops").CombineRaw("union all select * from OldLaptops");
SELECT * FROM [Laptops] union all select * from OldLaptops

Off course you can use the table identifier characters [ and ] to instruct SqlKata to wrap the tables/columns keywords.

//:playground
var mobiles = new Query("Laptops").CombineRaw("union all select * from [OldLaptops]");
SELECT * FROM [Laptops] union all select * from [OldLaptops]
Heap apparel

THE APPAREL BRAND FOR DEVELOPERS

one email per month about tips & tricks, new features, and maybe community feedback