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

javascript - How to get current YouTube IDs via iMacros? -

c# - Maintaining a program folder in program files out of date? -

emulation - Android map show my location didn't work -