There's a max_heap_table_size limit to 16 mb so how can i change this value and where?
I am pretty sure the max_heap_table_size is set to around 16MB by default. So I would first check what it is set to by running a query:
select @@max_heap_table_size;
And then you can run a query to set it higher:
set @@max_heap_table_size=NUMBER_OF_BYTES;