Ok, so I'm new to derived tables. When I run this query it gives me a MYSQL ERROR 1248. Anyone know of a work around for this? This is probably the most complex query I have done and I just want to get it to work. Thank you!
delete from table_1
where thing_id in (
select tid from(
select thing_id as tid
FROM table_1
inner join table_2
on table_1.thing_id = table_2.thing_id
where stuff = 'stuff'
)
)
MySQL normally does not allow you to reference the table being deleted (or updated) in the rest of the statement. You can get around this using nested subqueries (as you seem to be attempting to do). However, I think it is better to use explicit
join
s for the update:That said, I think this is equivalent to just doing the
join
ontable2
:This latter method should have better performance as well.