Overlap join with start and end positions

Overlap joins was implemented with commit 1375 in data.table v1.9.3, and is available in the current stable release, v1.9.4. The function is called foverlaps. From NEWS: 29) Overlap joins #528 is now here, finally!! Except for type=”equal” and maxgap and minoverlap arguments, everything else is implemented. Check out ?foverlaps and the examples there on its … Read more

How can I do three table JOINs in an UPDATE query?

The answer is yes, you can. Try it like this: UPDATE TABLE_A a JOIN TABLE_B b ON a.join_col = b.join_col AND a.column_a = b.column_b JOIN TABLE_C c ON [condition] SET a.column_c = a.column_c + 1 For a general update join: UPDATE TABLEA a JOIN TABLEB b ON a.join_colA = b.join_colB SET a.columnToUpdate = [something]

Find complement of a data frame (anti – join)

You could also do some type of anti join with data.tables binary join library(data.table) setkey(setDT(df), heads)[!df1] # heads # 1: row1 # 2: row2 # 3: row4 EDIT: Starting data.table v1.9.6+ we can join data.tables without setting keys while using on setDT(df)[!df1, on = “heads”] EDIT2: Starting data.table v1.9.8+ fsetdiff was introduced which is basically … Read more

LEFT OUTER JOIN in LINQ

As stated on: 101 LINQ Samples – Left outer join var q = from c in categories join p in products on c.Category equals p.Category into ps from p in ps.DefaultIfEmpty() select new { Category = c, ProductName = p == null ? “(No products)” : p.ProductName };

Join vs. sub-query

Sub-queries are the logically correct way to solve problems of the form, “Get facts from A, conditional on facts from B”. In such instances, it makes more logical sense to stick B in a sub-query than to do a join. It is also safer, in a practical sense, since you don’t have to be cautious … Read more

How do I perform the SQL Join equivalent in MongoDB?

As of Mongo 3.2 the answers to this question are mostly no longer correct. The new $lookup operator added to the aggregation pipeline is essentially identical to a left outer join: https://docs.mongodb.org/master/reference/operator/aggregation/lookup/#pipe._S_lookup From the docs: { $lookup: { from: <collection to join>, localField: <field from the input documents>, foreignField: <field from the documents of the … Read more

Explicit vs implicit SQL joins

Performance wise, they are exactly the same (at least in SQL Server). PS: Be aware that the IMPLICIT OUTER JOIN syntax is deprecated since SQL Server 2005. (The IMPLICIT INNER JOIN syntax as used in the question is still supported) Deprecation of “Old Style” JOIN Syntax: Only A Partial Thing

INNER JOIN ON vs WHERE clause

INNER JOIN is ANSI syntax that you should use. It is generally considered more readable, especially when you join lots of tables. It can also be easily replaced with an OUTER JOIN whenever a need arises. The WHERE syntax is more relational model oriented. A result of two tables JOINed is a cartesian product of … Read more