Returns ID's where 2nd columns is not unique.












1














In SQL, I am trying to find a formula that finds ID's with exactly the same tagnumbers as a different ID. So for:



ID    Tagnumber         
1 44
1 45
2 45
2 44
3 42
3 44
3 44
4 55
4 55
4 55
4 55


It should return 1 and 2, because these ID's have a tagnumber composition that is not unique. The order or the amount of tag ID's does not matter, if the same tag id's also exist under a different ID, it should be returned. Any help is appreciated!










share|improve this question





























    1














    In SQL, I am trying to find a formula that finds ID's with exactly the same tagnumbers as a different ID. So for:



    ID    Tagnumber         
    1 44
    1 45
    2 45
    2 44
    3 42
    3 44
    3 44
    4 55
    4 55
    4 55
    4 55


    It should return 1 and 2, because these ID's have a tagnumber composition that is not unique. The order or the amount of tag ID's does not matter, if the same tag id's also exist under a different ID, it should be returned. Any help is appreciated!










    share|improve this question



























      1












      1








      1







      In SQL, I am trying to find a formula that finds ID's with exactly the same tagnumbers as a different ID. So for:



      ID    Tagnumber         
      1 44
      1 45
      2 45
      2 44
      3 42
      3 44
      3 44
      4 55
      4 55
      4 55
      4 55


      It should return 1 and 2, because these ID's have a tagnumber composition that is not unique. The order or the amount of tag ID's does not matter, if the same tag id's also exist under a different ID, it should be returned. Any help is appreciated!










      share|improve this question















      In SQL, I am trying to find a formula that finds ID's with exactly the same tagnumbers as a different ID. So for:



      ID    Tagnumber         
      1 44
      1 45
      2 45
      2 44
      3 42
      3 44
      3 44
      4 55
      4 55
      4 55
      4 55


      It should return 1 and 2, because these ID's have a tagnumber composition that is not unique. The order or the amount of tag ID's does not matter, if the same tag id's also exist under a different ID, it should be returned. Any help is appreciated!







      mysql sql






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 at 12:26

























      asked Nov 22 at 12:24









      Dechesne

      155




      155
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You can use aggregation:



          select tags, group_concat(id order by id) as ids
          from (select id, group_concat(tagnumber order by tagnumber) as tags
          from t
          group by id
          ) i
          group by tags
          having count(*) > 1;





          share|improve this answer





















          • Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
            – Dechesne
            Nov 22 at 12:49








          • 1




            @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
            – Madhur Bhaiya
            Nov 22 at 16:22






          • 1




            Thanks for your help Madhur.
            – Dechesne
            Nov 22 at 17:30











          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%2f53430962%2freturns-ids-where-2nd-columns-is-not-unique%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          0














          You can use aggregation:



          select tags, group_concat(id order by id) as ids
          from (select id, group_concat(tagnumber order by tagnumber) as tags
          from t
          group by id
          ) i
          group by tags
          having count(*) > 1;





          share|improve this answer





















          • Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
            – Dechesne
            Nov 22 at 12:49








          • 1




            @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
            – Madhur Bhaiya
            Nov 22 at 16:22






          • 1




            Thanks for your help Madhur.
            – Dechesne
            Nov 22 at 17:30
















          0














          You can use aggregation:



          select tags, group_concat(id order by id) as ids
          from (select id, group_concat(tagnumber order by tagnumber) as tags
          from t
          group by id
          ) i
          group by tags
          having count(*) > 1;





          share|improve this answer





















          • Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
            – Dechesne
            Nov 22 at 12:49








          • 1




            @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
            – Madhur Bhaiya
            Nov 22 at 16:22






          • 1




            Thanks for your help Madhur.
            – Dechesne
            Nov 22 at 17:30














          0












          0








          0






          You can use aggregation:



          select tags, group_concat(id order by id) as ids
          from (select id, group_concat(tagnumber order by tagnumber) as tags
          from t
          group by id
          ) i
          group by tags
          having count(*) > 1;





          share|improve this answer












          You can use aggregation:



          select tags, group_concat(id order by id) as ids
          from (select id, group_concat(tagnumber order by tagnumber) as tags
          from t
          group by id
          ) i
          group by tags
          having count(*) > 1;






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 at 12:25









          Gordon Linoff

          755k35290398




          755k35290398












          • Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
            – Dechesne
            Nov 22 at 12:49








          • 1




            @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
            – Madhur Bhaiya
            Nov 22 at 16:22






          • 1




            Thanks for your help Madhur.
            – Dechesne
            Nov 22 at 17:30


















          • Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
            – Dechesne
            Nov 22 at 12:49








          • 1




            @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
            – Madhur Bhaiya
            Nov 22 at 16:22






          • 1




            Thanks for your help Madhur.
            – Dechesne
            Nov 22 at 17:30
















          Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
          – Dechesne
          Nov 22 at 12:49






          Getting an error: "unknown column 'tagnumber' in 'field list'" I checked the column at it should be correct.
          – Dechesne
          Nov 22 at 12:49






          1




          1




          @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
          – Madhur Bhaiya
          Nov 22 at 16:22




          @Dechesne this answer is correct. I interpreted it wrong. Removing my answer.
          – Madhur Bhaiya
          Nov 22 at 16:22




          1




          1




          Thanks for your help Madhur.
          – Dechesne
          Nov 22 at 17:30




          Thanks for your help Madhur.
          – Dechesne
          Nov 22 at 17:30


















          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.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • 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%2f53430962%2freturns-ids-where-2nd-columns-is-not-unique%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

          Berounka

          Sphinx de Gizeh

          Different font size/position of beamer's navigation symbols template's content depending on regular/plain...