SQL: Finding the total number of items for each category and ordering the resultWhat is the best way to paginate results in SQL ServerSQL to find the number of distinct values in a columnHow do I limit the number of rows returned by an Oracle query after ordering?SQL multiple column orderingFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerFind duplicate lines in a file and count how many time each line was duplicated?Database design for products with multiple categories and multiple sub-featuresMySQL: Sort items by category countSQL: Counting the total number of distinct items within a category

Write The Shortest Program to Calculate Height of a Binary Tree

Is it okay to use different fingers every time while playing a song on keyboard? Is it considered a bad practice?

Repeated! Factorials!

Vectorised way to calculate mean of left and right neighbours in a vector

Can you put ranks into knowledge skills that aren't class skills?

Why do rocket engines use nitrogen actuators to operate the fuel/oxidiser valves instead of electric servos?

Is an "are" omitted in this sentence

Has J.J.Jameson ever found out that Peter Parker is Spider-Man?

split inside flalign

Why is the Vasa Museum in Stockholm so Popular?

How do people drown while wearing a life jacket?

Is it uncompelling to continue the story with lower stakes?

How do I show and not tell a backstory?

Need reasons why a satellite network would not work

Did Logical Positivism fail because it simply denied human emotion?

How to check a file was encrypted (really & correctly)

Why did the US Airways Flight 1549 passengers stay on the wings?

Is there a general term for the items in a directory?

Variable doesn't parse as string

Formal mathematical definition of renormalization group flow

Is there a way to improve my grade after graduation?

How do the surviving Asgardians get to Earth?

What do "unsettled funds" mean?

Pronouns when writing from the point of view of a robot



SQL: Finding the total number of items for each category and ordering the result


What is the best way to paginate results in SQL ServerSQL to find the number of distinct values in a columnHow do I limit the number of rows returned by an Oracle query after ordering?SQL multiple column orderingFinding duplicate values in a SQL tableFind all tables containing column with specified name - MS SQL ServerFind duplicate lines in a file and count how many time each line was duplicated?Database design for products with multiple categories and multiple sub-featuresMySQL: Sort items by category countSQL: Counting the total number of distinct items within a category






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have the following table called Field:



Category | Industry | Company
Research Science Biolite
Retail Healthcare The Vitamin Shop
Crafts Stationery Art Centre
Research Science GeneSys
Retail Healthcare Live Healthy
Crafts Stationery Typewrite Pens


I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):



Category | Industry | Number
Research Science 2
Retail Healthcare 2
Crafts Stationery 2


I have the following query:



select t1.Category, t1.Industry, t2.Number from Field t1
inner join (
select Industry, count(*) as Number from Field
group by Industry
) t2
on t1.Industry = t2.Industry;


However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?










share|improve this question






























    0















    I have the following table called Field:



    Category | Industry | Company
    Research Science Biolite
    Retail Healthcare The Vitamin Shop
    Crafts Stationery Art Centre
    Research Science GeneSys
    Retail Healthcare Live Healthy
    Crafts Stationery Typewrite Pens


    I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):



    Category | Industry | Number
    Research Science 2
    Retail Healthcare 2
    Crafts Stationery 2


    I have the following query:



    select t1.Category, t1.Industry, t2.Number from Field t1
    inner join (
    select Industry, count(*) as Number from Field
    group by Industry
    ) t2
    on t1.Industry = t2.Industry;


    However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?










    share|improve this question


























      0












      0








      0








      I have the following table called Field:



      Category | Industry | Company
      Research Science Biolite
      Retail Healthcare The Vitamin Shop
      Crafts Stationery Art Centre
      Research Science GeneSys
      Retail Healthcare Live Healthy
      Crafts Stationery Typewrite Pens


      I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):



      Category | Industry | Number
      Research Science 2
      Retail Healthcare 2
      Crafts Stationery 2


      I have the following query:



      select t1.Category, t1.Industry, t2.Number from Field t1
      inner join (
      select Industry, count(*) as Number from Field
      group by Industry
      ) t2
      on t1.Industry = t2.Industry;


      However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?










      share|improve this question














      I have the following table called Field:



      Category | Industry | Company
      Research Science Biolite
      Retail Healthcare The Vitamin Shop
      Crafts Stationery Art Centre
      Research Science GeneSys
      Retail Healthcare Live Healthy
      Crafts Stationery Typewrite Pens


      I want to be able to find the total number of companies per industry, and then order the result by Category and then Industry. (E.g. for Science there would be 2 companies, for Healthcare there would be 2 companies and for Stationery there would be 2 companies as well). The output should look like this (unordered):



      Category | Industry | Number
      Research Science 2
      Retail Healthcare 2
      Crafts Stationery 2


      I have the following query:



      select t1.Category, t1.Industry, t2.Number from Field t1
      inner join (
      select Industry, count(*) as Number from Field
      group by Industry
      ) t2
      on t1.Industry = t2.Industry;


      However, in the resulting table, in the Industry column, duplicate industries are shown (e.g. Science shows up twice). How can I get the Industry column to show each industry only once?







      mysql sql count






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Mar 27 at 2:49









      ceno980ceno980

      6902 silver badges6 bronze badges




      6902 silver badges6 bronze badges

























          1 Answer
          1






          active

          oldest

          votes


















          2














          Grouping by both Category and Industry:



          select Category,Industry, count(*) as 'Number'
          from Field
          group by Category,Industry





          share|improve this answer

























          • SQLFiddle for this answer

            – esqew
            Mar 27 at 2:59










          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%2f55369066%2fsql-finding-the-total-number-of-items-for-each-category-and-ordering-the-result%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









          2














          Grouping by both Category and Industry:



          select Category,Industry, count(*) as 'Number'
          from Field
          group by Category,Industry





          share|improve this answer

























          • SQLFiddle for this answer

            – esqew
            Mar 27 at 2:59















          2














          Grouping by both Category and Industry:



          select Category,Industry, count(*) as 'Number'
          from Field
          group by Category,Industry





          share|improve this answer

























          • SQLFiddle for this answer

            – esqew
            Mar 27 at 2:59













          2












          2








          2







          Grouping by both Category and Industry:



          select Category,Industry, count(*) as 'Number'
          from Field
          group by Category,Industry





          share|improve this answer













          Grouping by both Category and Industry:



          select Category,Industry, count(*) as 'Number'
          from Field
          group by Category,Industry






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Mar 27 at 2:57









          danblackdanblack

          3,5381 gold badge4 silver badges22 bronze badges




          3,5381 gold badge4 silver badges22 bronze badges















          • SQLFiddle for this answer

            – esqew
            Mar 27 at 2:59

















          • SQLFiddle for this answer

            – esqew
            Mar 27 at 2:59
















          SQLFiddle for this answer

          – esqew
          Mar 27 at 2:59





          SQLFiddle for this answer

          – esqew
          Mar 27 at 2:59








          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







          Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















          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%2f55369066%2fsql-finding-the-total-number-of-items-for-each-category-and-ordering-the-result%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

          Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

          SQL error code 1064 with creating Laravel foreign keysForeign key constraints: When to use ON UPDATE and ON DELETEDropping column with foreign key Laravel error: General error: 1025 Error on renameLaravel SQL Can't create tableLaravel Migration foreign key errorLaravel php artisan migrate:refresh giving a syntax errorSQLSTATE[42S01]: Base table or view already exists or Base table or view already exists: 1050 Tableerror in migrating laravel file to xampp serverSyntax error or access violation: 1064:syntax to use near 'unsigned not null, modelName varchar(191) not null, title varchar(191) not nLaravel cannot create new table field in mysqlLaravel 5.7:Last migration creates table but is not registered in the migration table

          은진 송씨 목차 역사 본관 분파 인물 조선 왕실과의 인척 관계 집성촌 항렬자 인구 같이 보기 각주 둘러보기 메뉴은진 송씨세종실록 149권, 지리지 충청도 공주목 은진현