Custom SQL queries are a bit outside the scope of support we offer here in the forums when there are built-in features available for the same purpose. I don't have a simple cut-and-paste SQL script available, but I can show you another way to get related post IDs using our post relationships API toolset_get_related_posts.
Add the following code to your child theme's functions.php file, or append the code to the end of a new snippet in Toolset Settings > Custom Code tab, set the snippet to run everywhere, and activate the snippet.
/** 
 * Output a comma-separated list of child post IDs given parent post ID and slug of O2M
 * https://toolset.com/forums/topic/difference-between-wp_toolset_associations-and-wp_toolset_associations_old/
 * @relslug, string, required: Slug of the o2m post relationship
 * @paramid, integer, required: ID of parent post
 * 
 * EXAMPLE
 * Child post IDs: [tssupp-get-child-ids relslug="your-relationship-slug" parentid="12345"][/tssupp-get-child-ids]
 */
add_shortcode( 'tssupp-get-child-ids', 'tssupp_get_child_ids_func');
function tssupp_get_child_ids_func($atts)
{
  $limit = 1000;
  $default_rel_slug = 'your-relationship-slug';
  // you should not edit below this line
  $a = shortcode_atts( array(
    'relslug' => $default_rel_slug,
    'parentid' => 0,
  ), $atts );
  $children = toolset_get_related_posts(
    $a['parentid'],
    $a['relslug'],
    [
      'query_by_role'   => 'parent',
      'limit'           => $limit,
      'offset'          => 0,
      'args'            => [],
      'role_to_return'  => 'other',
    ],
  );
  $child_list = implode(',', $children);
  return $child_list;
}
 
The limit is currently set at 1000 related posts, but you can increase that for larger sites if necessary. A positive integer value is required instead of 1000.
Use the shortcode like so to output a comma-separated list of child post IDs for a known parent post ID in a specific post relationship:
Comma-separated list of child post IDs for parent post ID <strong>12345</strong> in post relationship <strong>your-relationship-slug:</strong><br />
[tssupp-get-child-ids relslug="your-relationship-slug" parentid="12345"][/tssupp-get-child-ids]<br />
Comma-separated list of child post IDs for parent post ID <strong>67890</strong> in post relationship <strong>your-other-relationship-slug:</strong><br />
[tssupp-get-child-ids relslug="your-other-relationship-slug" parentid="67890"][/tssupp-get-child-ids]<br />
 
You can see in the example here how to use the shortcode multiple times to output the child post IDs for mulitple parent posts from different post relationships. It's a simple but effective way to get the post IDs you described..
Documentation for the post relationships API toolset_get_related_posts:
https://toolset.com/documentation/customizing-sites-using-php/post-relationships-api/#toolset_get_related_posts