Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. Sql query

Sql query

Scheduled Pinned Locked Moved Database
database
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sarah_chandran
    wrote on last edited by
    #1

    If table1 has fields Studentname , departmentid and table2 has fields departmentid,departmentname then can anyone give me the sql query to get the department name and the number of students in each department.

    W V S 3 Replies Last reply
    0
    • S sarah_chandran

      If table1 has fields Studentname , departmentid and table2 has fields departmentid,departmentname then can anyone give me the sql query to get the department name and the number of students in each department.

      W Offline
      W Offline
      Wendelius
      wrote on last edited by
      #2

      Sounds like homework. Simply join and fetch the data from both tables and then group by department name. Use COUNT to calculate the amount of students.

      The need to optimize rises from a bad design.My articles[^]

      1 Reply Last reply
      0
      • S sarah_chandran

        If table1 has fields Studentname , departmentid and table2 has fields departmentid,departmentname then can anyone give me the sql query to get the department name and the number of students in each department.

        V Offline
        V Offline
        Vimalsoft Pty Ltd
        wrote on last edited by
        #3

        Try this

        SELECT Studentname , departmentid
        FROM TABLE1 T1 INNER JOIN TABLE2 T2 ON
        T1.departmentid = T2.departmentid
        ORDER BY departmentid

        Hope it helps

        Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswam@its.co.za

        C 1 Reply Last reply
        0
        • V Vimalsoft Pty Ltd

          Try this

          SELECT Studentname , departmentid
          FROM TABLE1 T1 INNER JOIN TABLE2 T2 ON
          T1.departmentid = T2.departmentid
          ORDER BY departmentid

          Hope it helps

          Vuyiswa Maseko, Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers." C#/VB.NET/ASP.NET/SQL7/2000/2005/2008 http://www.vuyiswamaseko.tiyaneProperties.co.za vuyiswam@its.co.za

          C Offline
          C Offline
          ChandraRam
          wrote on last edited by
          #4

          Vuyiswa Maseko wrote:

          Try this SELECT Studentname , departmentid FROM TABLE1 T1 INNER JOIN TABLE2 T2 ON T1.departmentid = T2.departmentid ORDER BY departmentid

          The OP wants department name and count of students - your query returns neither. ;P

          1 Reply Last reply
          0
          • S sarah_chandran

            If table1 has fields Studentname , departmentid and table2 has fields departmentid,departmentname then can anyone give me the sql query to get the department name and the number of students in each department.

            S Offline
            S Offline
            sarah_chandran
            wrote on last edited by
            #5

            Thank u , just what I needed. select deptname,COUNT(deptid) from emp,department where emp.deptid =department.id group by deptname

            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups