i'm quite a newbie with MySQL and i'm trying to create a table using a select * into. My problem is that i'm using a subquery and i don't understand the right sintax for the query. Morover, with this query i'll display all the record that i want to copy:
select trasco_titolarita.*
from trasco_titolarita
inner join (
select max(id) as maxID, soggetto_id
from trasco_titolarita group by soggetto_id
) maxID
on maxID.maxID = trasco_titolarita.id
as above, this query displays all the record that i'm interested in. The goal i want to achieve, is to copy all these records into another new table, so i was trying this:
select * into newtable from
(
select trasco_titolarita.*
from trasco_titolarita
inner join (
select max(id) as maxID, soggetto_id
from trasco_titolarita group by soggetto_id
) maxID
on maxID.maxID = trasco_titolarita.id
)
but this actually doesn't work, for a reasong i think is that the first select in the subquery is just a display. The error i get is "Incorrect syntax near ')' " Can someone give me some tips?