Select unique values of 3 columns from a sql table which has 7 columns












-1















This is what my table looks like.



I want to get unique 'sets' of origin, destination, and flight_date.



So, for the table shown, my query should return {['BLR','DEL', '2019-01-10'], ['BLR','DEL', '2019-01-11']}










share|improve this question





























    -1















    This is what my table looks like.



    I want to get unique 'sets' of origin, destination, and flight_date.



    So, for the table shown, my query should return {['BLR','DEL', '2019-01-10'], ['BLR','DEL', '2019-01-11']}










    share|improve this question



























      -1












      -1








      -1








      This is what my table looks like.



      I want to get unique 'sets' of origin, destination, and flight_date.



      So, for the table shown, my query should return {['BLR','DEL', '2019-01-10'], ['BLR','DEL', '2019-01-11']}










      share|improve this question
















      This is what my table looks like.



      I want to get unique 'sets' of origin, destination, and flight_date.



      So, for the table shown, my query should return {['BLR','DEL', '2019-01-10'], ['BLR','DEL', '2019-01-11']}







      javascript mysql node.js






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited 4 hours ago







      Khadar111

















      asked Jan 8 at 12:55









      Khadar111Khadar111

      146




      146
























          2 Answers
          2






          active

          oldest

          votes


















          1














          In MySQL this should do the trick:



          SELECT DISTINCT origin, destination, flight_date FROM flights


          Alternatively:



          SELECT origin, destination, flight_date 
          FROM flights
          GROUP BY origin, destination, flight_date


          DISTINCT basically means "Make sure the rows are unique", wheras the advantage of using GROUP BY is, that you can use aggregate functions with it (summing, average etc). Also you can add additional conditions using HAVING.



          Example:



          SELECT origin, destination, flight_date, SUM(time_bucket) AS time_bucket_total
          FROM flights
          GROUP BY origin, destination, flight_date
          HAVING SUM(time_bucket) > 3


          This will return the summed time_bucket values along each row, and will also return only those entries where that sum is greater than 3.






          share|improve this answer


























          • It works! is either of the above more efficient than the other?

            – Khadar111
            Jan 8 at 13:07











          • @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

            – NappingRabbit
            Jan 8 at 13:13











          • @NappingRabbit Can you elaborate on how the second one provides more flexibility?

            – Khadar111
            Jan 8 at 13:26













          • @Khadar111, I've edited and elaborated the post.

            – Markus Klein
            yesterday



















          0














          Add group by the columns you want to select unique values of






          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%2f54092278%2fselect-unique-values-of-3-columns-from-a-sql-table-which-has-7-columns%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            In MySQL this should do the trick:



            SELECT DISTINCT origin, destination, flight_date FROM flights


            Alternatively:



            SELECT origin, destination, flight_date 
            FROM flights
            GROUP BY origin, destination, flight_date


            DISTINCT basically means "Make sure the rows are unique", wheras the advantage of using GROUP BY is, that you can use aggregate functions with it (summing, average etc). Also you can add additional conditions using HAVING.



            Example:



            SELECT origin, destination, flight_date, SUM(time_bucket) AS time_bucket_total
            FROM flights
            GROUP BY origin, destination, flight_date
            HAVING SUM(time_bucket) > 3


            This will return the summed time_bucket values along each row, and will also return only those entries where that sum is greater than 3.






            share|improve this answer


























            • It works! is either of the above more efficient than the other?

              – Khadar111
              Jan 8 at 13:07











            • @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

              – NappingRabbit
              Jan 8 at 13:13











            • @NappingRabbit Can you elaborate on how the second one provides more flexibility?

              – Khadar111
              Jan 8 at 13:26













            • @Khadar111, I've edited and elaborated the post.

              – Markus Klein
              yesterday
















            1














            In MySQL this should do the trick:



            SELECT DISTINCT origin, destination, flight_date FROM flights


            Alternatively:



            SELECT origin, destination, flight_date 
            FROM flights
            GROUP BY origin, destination, flight_date


            DISTINCT basically means "Make sure the rows are unique", wheras the advantage of using GROUP BY is, that you can use aggregate functions with it (summing, average etc). Also you can add additional conditions using HAVING.



            Example:



            SELECT origin, destination, flight_date, SUM(time_bucket) AS time_bucket_total
            FROM flights
            GROUP BY origin, destination, flight_date
            HAVING SUM(time_bucket) > 3


            This will return the summed time_bucket values along each row, and will also return only those entries where that sum is greater than 3.






            share|improve this answer


























            • It works! is either of the above more efficient than the other?

              – Khadar111
              Jan 8 at 13:07











            • @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

              – NappingRabbit
              Jan 8 at 13:13











            • @NappingRabbit Can you elaborate on how the second one provides more flexibility?

              – Khadar111
              Jan 8 at 13:26













            • @Khadar111, I've edited and elaborated the post.

              – Markus Klein
              yesterday














            1












            1








            1







            In MySQL this should do the trick:



            SELECT DISTINCT origin, destination, flight_date FROM flights


            Alternatively:



            SELECT origin, destination, flight_date 
            FROM flights
            GROUP BY origin, destination, flight_date


            DISTINCT basically means "Make sure the rows are unique", wheras the advantage of using GROUP BY is, that you can use aggregate functions with it (summing, average etc). Also you can add additional conditions using HAVING.



            Example:



            SELECT origin, destination, flight_date, SUM(time_bucket) AS time_bucket_total
            FROM flights
            GROUP BY origin, destination, flight_date
            HAVING SUM(time_bucket) > 3


            This will return the summed time_bucket values along each row, and will also return only those entries where that sum is greater than 3.






            share|improve this answer















            In MySQL this should do the trick:



            SELECT DISTINCT origin, destination, flight_date FROM flights


            Alternatively:



            SELECT origin, destination, flight_date 
            FROM flights
            GROUP BY origin, destination, flight_date


            DISTINCT basically means "Make sure the rows are unique", wheras the advantage of using GROUP BY is, that you can use aggregate functions with it (summing, average etc). Also you can add additional conditions using HAVING.



            Example:



            SELECT origin, destination, flight_date, SUM(time_bucket) AS time_bucket_total
            FROM flights
            GROUP BY origin, destination, flight_date
            HAVING SUM(time_bucket) > 3


            This will return the summed time_bucket values along each row, and will also return only those entries where that sum is greater than 3.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered Jan 8 at 12:59









            Markus KleinMarkus Klein

            112




            112













            • It works! is either of the above more efficient than the other?

              – Khadar111
              Jan 8 at 13:07











            • @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

              – NappingRabbit
              Jan 8 at 13:13











            • @NappingRabbit Can you elaborate on how the second one provides more flexibility?

              – Khadar111
              Jan 8 at 13:26













            • @Khadar111, I've edited and elaborated the post.

              – Markus Klein
              yesterday



















            • It works! is either of the above more efficient than the other?

              – Khadar111
              Jan 8 at 13:07











            • @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

              – NappingRabbit
              Jan 8 at 13:13











            • @NappingRabbit Can you elaborate on how the second one provides more flexibility?

              – Khadar111
              Jan 8 at 13:26













            • @Khadar111, I've edited and elaborated the post.

              – Markus Klein
              yesterday

















            It works! is either of the above more efficient than the other?

            – Khadar111
            Jan 8 at 13:07





            It works! is either of the above more efficient than the other?

            – Khadar111
            Jan 8 at 13:07













            @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

            – NappingRabbit
            Jan 8 at 13:13





            @Khadar111 the performance difference is trivial between the two. I like the top one personally, but the second one potentially provides more flexiblity

            – NappingRabbit
            Jan 8 at 13:13













            @NappingRabbit Can you elaborate on how the second one provides more flexibility?

            – Khadar111
            Jan 8 at 13:26







            @NappingRabbit Can you elaborate on how the second one provides more flexibility?

            – Khadar111
            Jan 8 at 13:26















            @Khadar111, I've edited and elaborated the post.

            – Markus Klein
            yesterday





            @Khadar111, I've edited and elaborated the post.

            – Markus Klein
            yesterday













            0














            Add group by the columns you want to select unique values of






            share|improve this answer




























              0














              Add group by the columns you want to select unique values of






              share|improve this answer


























                0












                0








                0







                Add group by the columns you want to select unique values of






                share|improve this answer













                Add group by the columns you want to select unique values of







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 8 at 13:03









                BoscoBosco

                294




                294






























                    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%2f54092278%2fselect-unique-values-of-3-columns-from-a-sql-table-which-has-7-columns%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

                    Homophylophilia

                    Updating UILabel text programmatically using a function

                    Cloud Functions - OpenCV Videocapture Read method fails for larger files from cloud storage