First of all, integrated tables are the best solution (they are made just for what you are trying to do manually). But you do not want them, so here is the next best thing:
For something more complex than your first example, you must simulate the remote table manually by inserting the contents of the table instead of the table.
I will rewrite your first example this way, because your second example is corrupted, and I donโt even know what you want to express exactly there.
When using 1 server, you had the following code:
select name from Enterprise E inner join Users U on E.cod = U.cod where E.cod = $my_code and U.codUsers in ($users);
Now you can replace the table with actual table data:
select name from Enterprise E inner join ( select 1 as cod, 4 as codUsers, 20 as codHistory union select 2 as cod, 8 as codUsers, 500 as codHistory union select 3 as cod, 29 as codUsers, 100 as codHistory ) as U on E.cod = U.cod where E.cod = $my_code and U.codUsers in ($users);
To do this, you need to collect the table data as a string (I use pdo here):
foreach($db->query('select * from Users U where U.codUsers in ($users)') as $row) { if($data !== '') { $data .= 'union '; } $data .= 'select ' . $row['cod'] . ' as cod, ' . $row['codUsers'] . ' as codUsers, ' . $row['codHistory'] . ' as codHistory '; }
You should put it in the layout of your user table, of course (and don't forget some "for row columns"), and you can omit columns that you don't need.
Now you can place this line anywhere where your Users table used to be and write your code as if it were on 1 server, so your first code will look like
select name from Enterprise E inner join ($data) as U on E.cod = U.cod where E.cod = $my_code and U.codUsers in ($users);
and your second code (although I remind you that it does not work and does not work on 1 server) will look like
select e.name, e.datebegin, e.dateend from Enterprise E leftjoin ( select h.callQuantity, h.history from thirdtable inner join ($data) as u on e.cod = u.cod where u.codHistory in (1,2,3) group by u.cod)
You have to make sure that you have a small number of users in your $ data line, then this will work fine. Otherwise, you will need join tables.