How to join the column from Table B to Table A on some condition

Before posting my question here, I was researching the other posts on stackoverflow and other resources. They haven't solved my problem(. Can you help me? Lets go to the point.

I have my movies table with columns(id, name, kind_id, production_year) and i have movies_info table with (id, movie_id, info). I want to join my info column to the movies table. And then select everything from movies and the joined column info on some condition. I have built the next query, but somehow it still doesn't work correctly.

    String query = "SELECT m.*, m_i.info FROM movies m " +
                   "INNER JOIN movie_info m_i ON m.id = m_i.movie_id "+
                   "WHERE m.production_year <=' " + array[1] + "' 
                   AND m.production_year >= ' " + array[0] +" 'AND m.kind_id=1";

i think here is something wrong with my wherecondition. I hope the question was clear.

Thanks in advance

Answers


Change INNER JOIN to LEFT JOIN.

String query = "SELECT m.*, m_i.info FROM movies m " +
               "LEFT JOIN movie_info m_i ON m.id = m_i.movie_id "+
               "WHERE m.production_year <=' " + array[1] + "' 
               AND m.production_year >= ' " + array[0] +" 'AND m.kind_id=1";

Need Your Help

How to override JavaScript array sort method?

javascript sorting overriding overloading

THIS QUESTION STILL HAS NOT BEEN CORRECTED ANSWERED AS OF Monday Oct 31 (People are wrongly answer it as if I'm asking for array.sort to be modified but I'm not asking that)