Join/Where with LINQ and Lambda

I find that if you’re familiar with SQL syntax, using the LINQ query syntax is much clearer, more natural, and makes it easier to spot errors: var id = 1; var query = from post in database.Posts join meta in database.Post_Metas on post.ID equals meta.Post_ID where post.ID == id select new { Post = post, … Read more

Inner join on two text files

Here’s an awk option, so you can avoid the bash dependency (for portability): $ awk -F’|’ ‘NR==FNR{check[$0];next} $2 in check’ file2 file1 How does this work? -F’|’ — sets the field separator ‘NR==FNR{check[$0];next} — if the total record number matches the file record number (i.e. we’re reading the first file provided), then we populate an … Read more

SQL JOIN – WHERE clause vs. ON clause

They are not the same thing. Consider these queries: SELECT * FROM Orders LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID WHERE Orders.ID = 12345 and SELECT * FROM Orders LEFT JOIN OrderLines ON OrderLines.OrderID=Orders.ID AND Orders.ID = 12345 The first will return an order and its lines, if any, for order number 12345. The second will return … Read more