I have these tables:
table_a
user_id
article_id
created_at
articles
user_id
created_at
...
I need to obtain all rows from both tables for the respective user (lets say user_id=1) and sorted them by the column created_at. How to do that?
I have tried to do it this way:
Model.find_by_sql('SELECT table_a.* FROM table_a JOIN articles ON articles.user_id = 1 WHERE table_a.user_id = 1')
But this query won't work.
ON articles.user_id = table_a.user_idYou should tell how you join the tableswon't workand give examples. Unexpected data, error messages, every time you run it the power in your office goes out and a purple goblin steals your mouse and keyboard?JOINprobably is not needed there... I just need to get all rows from both tables withuser_id=1User<-->UserArticles<-->Articles.