mysql - Sort and Join two tables by date -


i have following tables:

posts post_id | text    | posts_date 1       | blabla  | 06-06-2013 2       | bababa  | 09-06-2013 ... 

and

comments comment_id | post_id | user_id | text            | comments_date 1          | 1       | 55      | this...  | 06-08-2013 2          | 1       | 66      | yeah, me also!  | 06-07-2013 3          | 2       | 55      | this...  | 06-10-2013 4          | 2       | 66      | yeah, me also!  | 06-11-2013 ... 

i need sql statement returns columns both tables , orders them first posts_date , comments_date post.

so resulting table query should be

post_id | text    | posts_date  |  comment_id  | user_id | text            | comments_date 1       | blabla  | 06-06-2013  |   2          | 66      | yeah, me also!  | 06-07-2013 1       | blabla  | 06-06-2013  |   1          | 55      | this...  | 06-08-2013 2       | bababa  | 09-06-2013  |   3          | 55      | this...  | 06-10-2013 2       | bababa  | 09-06-2013  |   4          | 66      | yeah, me also!  | 06-11-2013 

i thought of like

select * comments c, (select * posts order posts_date asc) p p.post_id = c.post_id order comments_date asc 

but didn't seem give right results.

select *  comments c join posts p on c.post_id = p.post_id  order p.posts_date,c.comments_date asc 

Comments

Popular posts from this blog

Load Balancing in Bluemix using custom domain and DNS SRV records -

oracle - pls-00402 alias required in select list of cursor to avoid duplicate column names -

python - Consider setting $PYTHONHOME to <prefix>[:<exec_prefix>] error -