sql for querying post and their category

To get a specific post in WordPress, you can use the get_post() function and get_the_category() to get the categories associated with it. You can then use the code found in this answer to dump the SQL queries used.

<?php
$post_ID = 7;
$the_post = get_post( $post_ID );
$the_category = get_the_category( $post_ID );