SQL Performance UNION vs OR

Either the article you read used a bad example, or you misinterpreted their point. select username from users where company = ‘bbc’ or company = ‘itv’; This is equivalent to: select username from users where company IN (‘bbc’, ‘itv’); MySQL can use an index on company for this query just fine. There’s no need to … Read more

How to get matching data from another SQL table for two different columns: Inner Join and/or Union?

(The following applies when every row is SQL DISTINCT, and outside SQL code similarly treats NULL like just another value.) Every base table has a statement template, aka predicate, parameterized by column names, by which we put a row in or leave it out. We can use a (standard predicate logic) shorthand for the predicate … Read more

Intersection and union of ArrayLists in Java

Here’s a plain implementation without using any third-party library. Main advantage over retainAll, removeAll and addAll is that these methods don’t modify the original lists input to the methods. public class Test { public static void main(String… args) throws Exception { List<String> list1 = new ArrayList<String>(Arrays.asList(“A”, “B”, “C”)); List<String> list2 = new ArrayList<String>(Arrays.asList(“B”, “C”, “D”, … Read more