I have a production database in mysql and do some Junit tests in H2.
I am struggling to find a syntax that would both work in tests and production to delete records in 2 tables.
SQL queries are sent to the database using
jdbctemplate.update(sqlQuery, queryArgs);
So far I have found queries that work on mysql but not on H2 and vice versa.
I have 2 tables : requests and responses which have 2 columns in common datetime and milisec. The couple (datetime, milisec) is a primary key on requests, there can be several responses for the same couple.
I want to delete the responses that matches some of the requests.
This requests works fine with my sql but not with H2 :
DELETE r.*
FROM responses AS r NATURAL JOIN Call_requests AS s
WHERE -- criteria on call_requests table
The closest I have come with would be
DELETE FROM responses
where (datetime, milisec) in
(select datetime, milisec from requests where -- criteria)
this upper version works with mysql not with h2, where as the following with parentheses around the tuple is the reverse (works with h2, not mysql)
DELETE FROM responses
where (datetime, milisec) in
(select (datetime, milisec) from requests where -- criteria)
r.*
works !?!? I didn't know you could do that! – Littlest.*
means in this context. – Littlest