How to Query more than one Col1 in Col2?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • newbieBrian
    New Member
    • Nov 2007
    • 17

    How to Query more than one Col1 in Col2?

    Hi all,

    I have a table with two columns called for example instructor and class
    one instructor may teach more than one class. How can I query how many classes each instructor teaches?

    Let me make up the table.

    Instructor Class

    Mr. A physics
    Mr. A Calculus
    Ms.B Cooking for dummy
    Ms.B English

    Thanks
  • amitpatel66
    Recognized Expert Top Contributor
    • Mar 2007
    • 2358

    #2
    Originally posted by newbieBrian
    Hi all,

    I have a table with two columns called for example instructor and class
    one instructor may teach more than one class. How can I query how many classes each instructor teaches?

    Let me make up the table.

    Instructor Class

    Mr. A physics
    Mr. A Calculus
    Ms.B Cooking for dummy
    Ms.B English

    Thanks
    HINT: Make use of COUNT(class) and GRUOP BY instructor in the SELECT query

    Please POST what you have tried?

    Comment

    • newbieBrian
      New Member
      • Nov 2007
      • 17

      #3
      Originally posted by amitpatel66
      HINT: Make use of COUNT(class) and GRUOP BY instructor in the SELECT query

      Please POST what you have tried?
      [CODE=mysql]select instructor ,count(instruct or) from ThisTable group by instructor;[/CODE]

      I think it will work. My mine was dump yesterday. Thanks.
      Last edited by mwasif; Nov 16 '07, 02:57 PM. Reason: Added [CODE=mysql] tag

      Comment

      • mwasif
        Recognized Expert Contributor
        • Jul 2006
        • 802

        #4
        Well done newbieBrian. This query will work for you. If you also need the classes with the instructer, you can use GROUP_CONCAT() to get a list of comma separated classes.

        Comment

        • amitpatel66
          Recognized Expert Top Contributor
          • Mar 2007
          • 2358

          #5
          Originally posted by newbieBrian
          [CODE=mysql]select instructor ,count(instruct or) from ThisTable group by instructor;[/CODE]

          I think it will work. My mine was dump yesterday. Thanks.
          Good work NewbieBrian :)
          I appreciate

          MODERATOR

          Comment

          Working...