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. Question of beginer

Question of beginer

Scheduled Pinned Locked Moved Database
questiondatabasetutorial
7 Posts 3 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
    papa80
    wrote on last edited by
    #1

    Hi every body i need to know how to do one think.So i have to table one is Employer other is customerEmployer.Employer have idEmployer,name.CustomerEmployer have idemplpoyer and idcustomer. SO my question is please give me query who give it to me employer.name with max customet how to do that???:(( N.Nikolov best regards

    when i want to read something good just seat and type it

    C 1 Reply Last reply
    0
    • P papa80

      Hi every body i need to know how to do one think.So i have to table one is Employer other is customerEmployer.Employer have idEmployer,name.CustomerEmployer have idemplpoyer and idcustomer. SO my question is please give me query who give it to me employer.name with max customet how to do that???:(( N.Nikolov best regards

      when i want to read something good just seat and type it

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Your tables are:

      Employer

      IdEmployer
      Name

      CustomerEmployer

      IdEmployer
      IdCustomer

      This describes two thirds of a many-to-many join. The missing information is likely to be

      Customer

      IdCustomer
      {other columns}

      papa80 wrote:

      SO my question is please give me query who give it to me employer.name with max customet how to do that???

      What do you mean by max customer? What is a max customer? What defines the customer as being the max? If you mean the MAX(IdCustomer) then:

      SELECT Employer.Name
      FROM Employer
      INNER JOIN CustomerEmployer ON CustomerEmployer.IdEmployer = Employer.IdEmployer
      WHERE IdCustomer = (SELECT MAX(IdCustomer) FROM CustomerEmployer)


      * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

      P 1 Reply Last reply
      0
      • C Colin Angus Mackay

        Your tables are:

        Employer

        IdEmployer
        Name

        CustomerEmployer

        IdEmployer
        IdCustomer

        This describes two thirds of a many-to-many join. The missing information is likely to be

        Customer

        IdCustomer
        {other columns}

        papa80 wrote:

        SO my question is please give me query who give it to me employer.name with max customet how to do that???

        What do you mean by max customer? What is a max customer? What defines the customer as being the max? If you mean the MAX(IdCustomer) then:

        SELECT Employer.Name
        FROM Employer
        INNER JOIN CustomerEmployer ON CustomerEmployer.IdEmployer = Employer.IdEmployer
        WHERE IdCustomer = (SELECT MAX(IdCustomer) FROM CustomerEmployer)


        * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

        P Offline
        P Offline
        papa80
        wrote on last edited by
        #3

        is my bad.Ok i need to show employer.name with max number of customeres do you know how will look now that query???

        when i want to read something good just seat and type it

        C 1 Reply Last reply
        0
        • P papa80

          is my bad.Ok i need to show employer.name with max number of customeres do you know how will look now that query???

          when i want to read something good just seat and type it

          C Offline
          C Offline
          Colin Angus Mackay
          wrote on last edited by
          #4

          SELECT Employer.Name, CustomerCount.NumCustomers
          FROM Employer
          INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers
          FROM CustomerEmployer) AS CustomerCount
          ON CustomerCount.IdEmployer = Employer.IdEmployer


          * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

          P I 2 Replies Last reply
          0
          • C Colin Angus Mackay

            SELECT Employer.Name, CustomerCount.NumCustomers
            FROM Employer
            INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers
            FROM CustomerEmployer) AS CustomerCount
            ON CustomerCount.IdEmployer = Employer.IdEmployer


            * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

            P Offline
            P Offline
            papa80
            wrote on last edited by
            #5

            that is give me error Msg 8120, Level 16, State 1, Line 25 Column NumCustomers is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause. how to solv it??

            when i want to read something good just seat and type it

            1 Reply Last reply
            0
            • C Colin Angus Mackay

              SELECT Employer.Name, CustomerCount.NumCustomers
              FROM Employer
              INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers
              FROM CustomerEmployer) AS CustomerCount
              ON CustomerCount.IdEmployer = Employer.IdEmployer


              * Developer Day Scotland: are you interested in speaking or attending? My: Website | Blog

              I Offline
              I Offline
              i j russell
              wrote on last edited by
              #6

              Colin Angus Mackay wrote:

              SELECT Employer.Name, CustomerCount.NumCustomersFROM EmployerINNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers FROM CustomerEmployer) AS CustomerCountON CustomerCount.IdEmployer = Employer.IdEmployer

              You need to add ORDER BY CustomerCount.NumCustomers DESC to give you the maximum first. To get only the maximum, use SELECT TOP 1 Employer.Name, etc. SELECT TOP 1 Employer.[Name], CustomerCount.NumCustomers FROM Employer INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers FROM CustomerEmployer GROUP BY IdEmployer) AS CustomerCount ON CustomerCount.IdEmployer = Employer.IdEmployer ORDER BY CustomerCount.NumCustomers DESC Ian -- modified at 9:26 Thursday 17th August, 2006

              P 1 Reply Last reply
              0
              • I i j russell

                Colin Angus Mackay wrote:

                SELECT Employer.Name, CustomerCount.NumCustomersFROM EmployerINNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers FROM CustomerEmployer) AS CustomerCountON CustomerCount.IdEmployer = Employer.IdEmployer

                You need to add ORDER BY CustomerCount.NumCustomers DESC to give you the maximum first. To get only the maximum, use SELECT TOP 1 Employer.Name, etc. SELECT TOP 1 Employer.[Name], CustomerCount.NumCustomers FROM Employer INNER JOIN (SELECT IdEmployer, COUNT(*) AS NumCustomers FROM CustomerEmployer GROUP BY IdEmployer) AS CustomerCount ON CustomerCount.IdEmployer = Employer.IdEmployer ORDER BY CustomerCount.NumCustomers DESC Ian -- modified at 9:26 Thursday 17th August, 2006

                P Offline
                P Offline
                papa80
                wrote on last edited by
                #7

                Thank you very much.That is what i need.This code is great.:-D:)

                when i want to read something good just seat and type it

                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