wp sql查询获取帖子类别和媒体路径

I want to create json code of posts in wordpress. so I need post title, post categories and post media (if exist) I think first I should write a sql query. I wrote some thing like this for media but it doesn't help:

    SELECT t1.id, 
       t1.post_content, 
       t1.post_title, 
       t1.post_status, 
       t1.post_name, 
       t1.post_type 
FROM   `wp_posts` AS t1 
       JOIN `wp_posts` AS t2 
         ON t2.post_parent = t1.id 
WHERE  t1.post_type = 'post' 

and I use this for getting category fo posts:

SELECT p.post_title, t.name FROM wp_posts as p

join `wp_term_relationships` as tr on p.ID = tr.object_id

join wp_terms as t on tr.term_taxonomy_id=t.term_id

where p.post_type='post'

Can any one help?