

WHERE a. The heart of the library, the knex query builder is the interface used for. SELECT t1.name, t2.salary FROM employee AS t1 INNER JOIN info AS t2 ON t1.name t2.name SELECT t1.name, t2.salary FROM employee t1 INNER JOIN info t2 ON t1.name t2.name A tablesubquery is also known as a derived table or subquery in the FROM clause. SET TRANSACTION ISOLATION LEVEL READ-COMMITTED For this reason, I suggest you run this query in READ-COMMITTED combined with MIXED or ROW based replication. You're also going to get a performance hit from the unindexable LIKE %.Īnother consideration is, since this query will likely take a "while," in MySQL's default transaction isolation level of REPEATABLE READ, many of the rows in the tables in the SELECT statement will be locked due to gap locks, so will not be updatable. Instead, rewrite the query as a LEFT JOIN. I come across this on a weekly basis with developers on my team and it causes problems every time. Mysql> SELECT 1 UNION ALL SELECT 1 UNION SELECT 1 Īdditionally, NOT IN (SELECT) will execute the inner query for every row in the bounding query and is highly inefficient. SET BINLOGFORMATMIXED SET TRANSACTION ISOLATION LEVEL READ-COMMITTED INSERT INTO mybackuptable (accountid) SELECT a.id FROM accounts AS a WHERE a.createdate > datesub(now(), INTERVAL 1 YEAR) AND a.email NOT LIKE '') UNION SELECT a.id FROM accounts AS a LEFT JOIN inactiveclients ic USING(email) WHERE a.createdate < datesub.

I'm not sure if the optimizer will optimize away the unnecessary DISTINCTs, but consider this: mysql> SELECT 1 UNION ALL SELECT 1 UNION ALL SELECT 1 You actually don't need DISTINCT anywhere in this query as UNION implies DISTINCT. First, you are DISTINCTing too many times. Rolando answered your question regarding the INSERT syntax, but I'd like to add some additional comments regarding the performance of this query.
