if it’s the same database, you can write the query easily using the global $wpdb variable. If it’s a separate database, create another instance of wordpress wpdb class & write the queries to it $wpdb2 = new wpdb( $user, $pass, $db, $host );
In any case, you’ll need to know the database tables prefix
UPDATE
You can do it either way, either make the public site to insert the data to both databases or make the subdomain pick the data from both it’s own database & public database. Let’s say you want the 2nd approach
In this case you don’t want the public server to do anything, so let’s put it aside. Now in the subdomain’s template file, you’ll already have some code. There you will create a new instance of the wpdb class using the code above with the database details of the public server. Then you’ll write a query to the public database using this object. Check out the codex for details on how to do that
If you want to take the first approach, then also you’ll do it similarly except that the code is added to the public page’s code
Also you can do something like this to use wordpress functions
global $wpdb;
$temp = $wpdb;
$wpdb = new wpdb( $user, $pass, $db, $host );
// make the query here
$wpdb = $temp;
Though this will fail in some wordpress functions & i would recommend sticking with the direct query approach