Q:

SQL query to get post names and links from wordpress.org MySQL

I am writing a Python script to query my wordpress.org MySQL database. I want to query the post titles and their links so that I can build a custom Table of Contents page for my website. I have made a ToC page and have added an iframe to display the table of contents created by my Python script. 
So far I have the ToC page with an iframe and it loads the python script which queries the MySQL database. The python script is currently returning all post titles with this query:
    SELECT post_title
    FROM `wp_posts`
    WHERE post_type = 'post'
    AND post_status = 'publish';

However, I want my python script to organize my TOC based on Categories and I need the links for each article. How do I add the categories and links to my SQL query so that I output post_titles, links, and categories?

A:

I figured out what I needed to complete this project. The query below gives me everything I need to build a custom ToC for Wordpress. The post names and the post dates are needed to build the static links for each post. 
SELECT p.post_title as 'Post Title', 
       t.name as 'Category', 
       p.post_date as "Post Date", 
       p.post_name as "Post Name"
FROM wp_posts p, 
     wp_terms t, 
     wp_term_relationships tr, 
     wp_term_taxonomy tx
WHERE p.post_type = 'post'
AND p.post_status = 'publish'
AND tx.taxonomy = 'category'
AND p.ID = tr.object_id
AND tr.term_taxonomy_id = t.term_id
AND tx.term_id = t.term_id;

