retrieve the oldest post id

I do not see any problem in your query (except some poor query writing styles). You did not explain ‘does not work’. what you get in return? do you get any errors?

Probably you do not have any published job_listing!

However, here is how you can improve your given code:

$oldest_post_id = $wpdb->get_row("SELECT `id` FROM {$wpdb->posts} WHERE `post_type` = 'job_listing' AND `post_status` = 'publish' ORDER BY `post_date` ASC");

Please note the $wpdb->posts part. this will work safely in any wordpress installations even with custom table prefixes.

you should not use mysql_query directly. if you use this query inside a function, you need to include $wpdb in your function as below:

function myfunc(){
  global $wpdb;
  $wpdb->show_errors(true);
  $oldest_post_id = $wpdb->get_row("SELECT `id` FROM {$wpdb->posts} WHERE `post_type` = 'job_listing' AND `post_status` = 'publish' ORDER BY `post_date` ASC");
  var_dump($oldest_post_id);
}

now, you should get any query error displayed (if any) and var_dump() should give you the post ID. otherwise please get back to us what it is returning. when it is working remove 3rd and 5th line in the second example.