2

MEMSQL! I want to delete a record in a table that has a match in another table on multiple fields. Is this possible?

The MySql query I would use could be something like:

delete from t1 used t1,t2 where t1.f1=t2.f1 and t1.f2=t2.f2

or

delete t1 from t1,t2 where...

According to http://docs.memsql.com/docs/delete :

MemSQL does not yet fully support multi-table DELETE statements. Subqueries in the WHERE clause are the only multi-table DELETE allowed.

Can I use multiple conditions in delete where clause with out concat, etc?

P.S. Sorry for my terrible english

1

2 Answers 2

2

Try something like this:

delete from t1 where exists (select 1 from t2 where t1.f1=t2.f1 and t1.f2=t2.f2)
2
  • Thx for answer! For Select it worked. But delete got error "'correlated subselect that can not be transformed and does not match on shard keys' is not supported by memsql Distributed" Commented Oct 3, 2016 at 15:17
  • MemSQL currently has limited support for these query shapes if the joins are cross-shard. If you can make t1 and t2's shard keys include (f1, f2) then it should work. Another solution is making either of t1 and t2 a reference table.
    – Jack Chen
    Commented Oct 3, 2016 at 16:43
0

I had the same problem with trying to update some fields of a table from another table.

The problem is that Correlated subselect that can not be transformed and does not match on shard keys' is not supported by MemSQL Distributed So my solution was to create a select query that generates update queries and then to run them. Here is a simplified generator query:

select concat('update table1 set t1_code=\'',t2_code,
    '\',t1_url=\'',t2_url,
    '\',t1_width=\'',t2_width,
    '\' where t1.id=',t2.id,';') query
from t1
inner join t2 on t2.id=t1.id;

that generates update query for each row that needs update separated by ;.

Generating delete will be even easier - you can just select the ids to be deleted and generate a query delete from t1 where id in (-the list of ids that was selected for deletion-)

That was my workaround for this memsql restriction.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.