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. Nested Select query

Nested Select query

Scheduled Pinned Locked Moved Database
databasesql-serversysadminhelp
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.
  • P Offline
    P Offline
    Poonam Gandash
    wrote on last edited by
    #1

    "select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies) group by username,designation) order by points desc" this query works fine with MS Access but not with SQL Server. Through this query I am listing most active members of forum by counting no. of message and replies. Members are 2 types- Students & Professionals PLZ.... Help..

    K A V 3 Replies Last reply
    0
    • P Poonam Gandash

      "select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies) group by username,designation) order by points desc" this query works fine with MS Access but not with SQL Server. Through this query I am listing most active members of forum by counting no. of message and replies. Members are 2 types- Students & Professionals PLZ.... Help..

      K Offline
      K Offline
      Krish KP
      wrote on last edited by
      #2

      hope you are getting error message at group by clause if so, try this select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies )t1 group by username,designation )t2 order by points desc

      Regards KP

      P 1 Reply Last reply
      0
      • P Poonam Gandash

        "select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies) group by username,designation) order by points desc" this query works fine with MS Access but not with SQL Server. Through this query I am listing most active members of forum by counting no. of message and replies. Members are 2 types- Students & Professionals PLZ.... Help..

        A Offline
        A Offline
        andyharman
        wrote on last edited by
        #3

        Try:

        select * from (
          select username, designation, count(*) as points
          from (
            select username, designation from messages
            union all
            select username, designation from replies
          ) as A
          group by username, designation
        ) as B
        order by points desc
        

        You need to provide table aliases. I'm not sure where menber-types fit into this. Regards Andy

        1 Reply Last reply
        0
        • P Poonam Gandash

          "select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies) group by username,designation) order by points desc" this query works fine with MS Access but not with SQL Server. Through this query I am listing most active members of forum by counting no. of message and replies. Members are 2 types- Students & Professionals PLZ.... Help..

          V Offline
          V Offline
          vimal_yet
          wrote on last edited by
          #4

          What is the exact purpose of this Query ???

          If U Get Errors U Will Learn If U Don't Get Errors U Have Learnt

          1 Reply Last reply
          0
          • K Krish KP

            hope you are getting error message at group by clause if so, try this select * from (select username,designation, count(*) as points from (select username,designation from messages union all select username,designation from replies )t1 group by username,designation )t2 order by points desc

            Regards KP

            P Offline
            P Offline
            Poonam Gandash
            wrote on last edited by
            #5

            Thanks a lot it worked for me.. I rated u 5 This is 4 u :rose: :)

            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