How to get values through connected tables?












1















I have such a question. I got two tables, the first one contains comments, and the second id comments and album id to which the comment was left



> CREATE TABLE `review` (`id` VARCHAR(32) NOT NULL,
> `user_id` VARCHAR(32) NOT NULL,`comment` MEDIUMTEXT NOT NULL,
> PRIMARY KEY (`id`) )


> CREATE TABLE `review_album` (`review_id` VARCHAR(32) NOT NULL,
> `album_id` VARCHAR(32) NOT NULL, PRIMARY KEY (`review_id`,
> `album_id`), INDEX `review_album_review_idx` (`review_id`) )


I tried this way:



SELECT * from review_album JOIN review WHERE album_id = '300001' 


But i got result two times.



How can I get comment text for a specific album_id?










share|improve this question

























  • Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

    – P.Salmon
    Nov 15 '18 at 8:46
















1















I have such a question. I got two tables, the first one contains comments, and the second id comments and album id to which the comment was left



> CREATE TABLE `review` (`id` VARCHAR(32) NOT NULL,
> `user_id` VARCHAR(32) NOT NULL,`comment` MEDIUMTEXT NOT NULL,
> PRIMARY KEY (`id`) )


> CREATE TABLE `review_album` (`review_id` VARCHAR(32) NOT NULL,
> `album_id` VARCHAR(32) NOT NULL, PRIMARY KEY (`review_id`,
> `album_id`), INDEX `review_album_review_idx` (`review_id`) )


I tried this way:



SELECT * from review_album JOIN review WHERE album_id = '300001' 


But i got result two times.



How can I get comment text for a specific album_id?










share|improve this question

























  • Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

    – P.Salmon
    Nov 15 '18 at 8:46














1












1








1








I have such a question. I got two tables, the first one contains comments, and the second id comments and album id to which the comment was left



> CREATE TABLE `review` (`id` VARCHAR(32) NOT NULL,
> `user_id` VARCHAR(32) NOT NULL,`comment` MEDIUMTEXT NOT NULL,
> PRIMARY KEY (`id`) )


> CREATE TABLE `review_album` (`review_id` VARCHAR(32) NOT NULL,
> `album_id` VARCHAR(32) NOT NULL, PRIMARY KEY (`review_id`,
> `album_id`), INDEX `review_album_review_idx` (`review_id`) )


I tried this way:



SELECT * from review_album JOIN review WHERE album_id = '300001' 


But i got result two times.



How can I get comment text for a specific album_id?










share|improve this question
















I have such a question. I got two tables, the first one contains comments, and the second id comments and album id to which the comment was left



> CREATE TABLE `review` (`id` VARCHAR(32) NOT NULL,
> `user_id` VARCHAR(32) NOT NULL,`comment` MEDIUMTEXT NOT NULL,
> PRIMARY KEY (`id`) )


> CREATE TABLE `review_album` (`review_id` VARCHAR(32) NOT NULL,
> `album_id` VARCHAR(32) NOT NULL, PRIMARY KEY (`review_id`,
> `album_id`), INDEX `review_album_review_idx` (`review_id`) )


I tried this way:



SELECT * from review_album JOIN review WHERE album_id = '300001' 


But i got result two times.



How can I get comment text for a specific album_id?







mysql sql






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 15 '18 at 8:42







Mefisto_Fell

















asked Nov 15 '18 at 8:39









Mefisto_FellMefisto_Fell

326110




326110













  • Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

    – P.Salmon
    Nov 15 '18 at 8:46



















  • Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

    – P.Salmon
    Nov 15 '18 at 8:46

















Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

– P.Salmon
Nov 15 '18 at 8:46





Normally you would JOIN ON something without the ON clause you get a cross join/cartesian product.

– P.Salmon
Nov 15 '18 at 8:46












4 Answers
4






active

oldest

votes


















4














The general syntax is:



SELECT column-names
FROM table-name1 JOIN table-name2
ON column-name1 = column-name2
WHERE condition


The general syntax with INNER is:



SELECT column-names
FROM table-name1 INNER JOIN table-name2
ON column-name1 = column-name2
WHERE condition


Note: The INNER keyword is optional: it is the default as well as the most commonly used JOIN operation.



Refrence : https://www.dofactory.com/sql/join






share|improve this answer































    2














    Try with InnerJoin



    SELECT *
    FROM review_album
    JOIN review ON review_album.review_id=review.id
    WHERE album_id = '300001'


    Reference






    share|improve this answer































      1














      you have forgotten the on condition, everytime you have a join you'd better specify the condition of join, otherwais you have every connection available.
      Hovewer the solution



      SELECT * 
      FROM review_album RA
      JOIN review R ON RA.column_fk = R.column_fk
      WHERE album_id = '300001'


      Here the documentation for join https://www.w3schools.com/sql/sql_join.asp






      share|improve this answer
























      • The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

        – David Marabottini
        Nov 15 '18 at 9:10





















      1














          try using this :



      SELECT *
      FROM review_album ra
      JOIN review r ON rareview_id=r.id
      WHERE album_id = '300001'





      share|improve this answer























        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315332%2fhow-to-get-values-through-connected-tables%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        4














        The general syntax is:



        SELECT column-names
        FROM table-name1 JOIN table-name2
        ON column-name1 = column-name2
        WHERE condition


        The general syntax with INNER is:



        SELECT column-names
        FROM table-name1 INNER JOIN table-name2
        ON column-name1 = column-name2
        WHERE condition


        Note: The INNER keyword is optional: it is the default as well as the most commonly used JOIN operation.



        Refrence : https://www.dofactory.com/sql/join






        share|improve this answer




























          4














          The general syntax is:



          SELECT column-names
          FROM table-name1 JOIN table-name2
          ON column-name1 = column-name2
          WHERE condition


          The general syntax with INNER is:



          SELECT column-names
          FROM table-name1 INNER JOIN table-name2
          ON column-name1 = column-name2
          WHERE condition


          Note: The INNER keyword is optional: it is the default as well as the most commonly used JOIN operation.



          Refrence : https://www.dofactory.com/sql/join






          share|improve this answer


























            4












            4








            4







            The general syntax is:



            SELECT column-names
            FROM table-name1 JOIN table-name2
            ON column-name1 = column-name2
            WHERE condition


            The general syntax with INNER is:



            SELECT column-names
            FROM table-name1 INNER JOIN table-name2
            ON column-name1 = column-name2
            WHERE condition


            Note: The INNER keyword is optional: it is the default as well as the most commonly used JOIN operation.



            Refrence : https://www.dofactory.com/sql/join






            share|improve this answer













            The general syntax is:



            SELECT column-names
            FROM table-name1 JOIN table-name2
            ON column-name1 = column-name2
            WHERE condition


            The general syntax with INNER is:



            SELECT column-names
            FROM table-name1 INNER JOIN table-name2
            ON column-name1 = column-name2
            WHERE condition


            Note: The INNER keyword is optional: it is the default as well as the most commonly used JOIN operation.



            Refrence : https://www.dofactory.com/sql/join







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 15 '18 at 8:42









            Nasser Ali KarimiNasser Ali Karimi

            1,337532




            1,337532

























                2














                Try with InnerJoin



                SELECT *
                FROM review_album
                JOIN review ON review_album.review_id=review.id
                WHERE album_id = '300001'


                Reference






                share|improve this answer




























                  2














                  Try with InnerJoin



                  SELECT *
                  FROM review_album
                  JOIN review ON review_album.review_id=review.id
                  WHERE album_id = '300001'


                  Reference






                  share|improve this answer


























                    2












                    2








                    2







                    Try with InnerJoin



                    SELECT *
                    FROM review_album
                    JOIN review ON review_album.review_id=review.id
                    WHERE album_id = '300001'


                    Reference






                    share|improve this answer













                    Try with InnerJoin



                    SELECT *
                    FROM review_album
                    JOIN review ON review_album.review_id=review.id
                    WHERE album_id = '300001'


                    Reference







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 15 '18 at 8:43









                    SadikhasanSadikhasan

                    14.1k135994




                    14.1k135994























                        1














                        you have forgotten the on condition, everytime you have a join you'd better specify the condition of join, otherwais you have every connection available.
                        Hovewer the solution



                        SELECT * 
                        FROM review_album RA
                        JOIN review R ON RA.column_fk = R.column_fk
                        WHERE album_id = '300001'


                        Here the documentation for join https://www.w3schools.com/sql/sql_join.asp






                        share|improve this answer
























                        • The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                          – David Marabottini
                          Nov 15 '18 at 9:10


















                        1














                        you have forgotten the on condition, everytime you have a join you'd better specify the condition of join, otherwais you have every connection available.
                        Hovewer the solution



                        SELECT * 
                        FROM review_album RA
                        JOIN review R ON RA.column_fk = R.column_fk
                        WHERE album_id = '300001'


                        Here the documentation for join https://www.w3schools.com/sql/sql_join.asp






                        share|improve this answer
























                        • The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                          – David Marabottini
                          Nov 15 '18 at 9:10
















                        1












                        1








                        1







                        you have forgotten the on condition, everytime you have a join you'd better specify the condition of join, otherwais you have every connection available.
                        Hovewer the solution



                        SELECT * 
                        FROM review_album RA
                        JOIN review R ON RA.column_fk = R.column_fk
                        WHERE album_id = '300001'


                        Here the documentation for join https://www.w3schools.com/sql/sql_join.asp






                        share|improve this answer













                        you have forgotten the on condition, everytime you have a join you'd better specify the condition of join, otherwais you have every connection available.
                        Hovewer the solution



                        SELECT * 
                        FROM review_album RA
                        JOIN review R ON RA.column_fk = R.column_fk
                        WHERE album_id = '300001'


                        Here the documentation for join https://www.w3schools.com/sql/sql_join.asp







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Nov 15 '18 at 8:49









                        David MarabottiniDavid Marabottini

                        1707




                        1707













                        • The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                          – David Marabottini
                          Nov 15 '18 at 9:10





















                        • The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                          – David Marabottini
                          Nov 15 '18 at 9:10



















                        The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                        – David Marabottini
                        Nov 15 '18 at 9:10







                        The join without type is interpreted like inner join, but if you want use the inner join is better write inner join becaus it's more clear, however if you want another management of null you chan choise left outer join, right outer join or full outer yoin. I think you can find everything in the documentation that I passed in my reply

                        – David Marabottini
                        Nov 15 '18 at 9:10













                        1














                            try using this :



                        SELECT *
                        FROM review_album ra
                        JOIN review r ON rareview_id=r.id
                        WHERE album_id = '300001'





                        share|improve this answer




























                          1














                              try using this :



                          SELECT *
                          FROM review_album ra
                          JOIN review r ON rareview_id=r.id
                          WHERE album_id = '300001'





                          share|improve this answer


























                            1












                            1








                            1







                                try using this :



                            SELECT *
                            FROM review_album ra
                            JOIN review r ON rareview_id=r.id
                            WHERE album_id = '300001'





                            share|improve this answer













                                try using this :



                            SELECT *
                            FROM review_album ra
                            JOIN review r ON rareview_id=r.id
                            WHERE album_id = '300001'






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Nov 15 '18 at 9:27









                            Atul AkabariAtul Akabari

                            954




                            954






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Stack Overflow!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53315332%2fhow-to-get-values-through-connected-tables%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                Xamarin.iOS Cant Deploy on Iphone

                                Glorious Revolution

                                Dulmage-Mendelsohn matrix decomposition in Python