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. display all cleaners using Join

display all cleaners using Join

Scheduled Pinned Locked Moved Database
comannouncementcareerlearning
8 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    Hi, I am using the following code to populate all cleaners and display the income from every cleaner. It works fine when there is a entry for the cleaner in the job_order table but if no entry then it will not display the cleaner. I want to display ALL cleaners even if no entry in the job_order table but of course with ZERO income.

    SELECT
    cleaners.cleaner_id,
    cleaners.cleaner_name,
    cleaners.date_of_join,
    SUM(invoices.invoice_net_amount) as total_income
    FROM
    cleaners
    INNER JOIN job_orders ON job_orders.cleaner_id = cleaners.cleaner_id
    INNER JOIN invoices ON invoices.job_order_id = job_orders.job_order_id
    GROUP BY
    cleaners.cleaner_id
    ORDER BY cleaners.cleaner_name;

    Jassim XoomPage[^]

    Technology News @ www.JassimRahma.com

    L B D 3 Replies Last reply
    0
    • J Jassim Rahma

      Hi, I am using the following code to populate all cleaners and display the income from every cleaner. It works fine when there is a entry for the cleaner in the job_order table but if no entry then it will not display the cleaner. I want to display ALL cleaners even if no entry in the job_order table but of course with ZERO income.

      SELECT
      cleaners.cleaner_id,
      cleaners.cleaner_name,
      cleaners.date_of_join,
      SUM(invoices.invoice_net_amount) as total_income
      FROM
      cleaners
      INNER JOIN job_orders ON job_orders.cleaner_id = cleaners.cleaner_id
      INNER JOIN invoices ON invoices.job_order_id = job_orders.job_order_id
      GROUP BY
      cleaners.cleaner_id
      ORDER BY cleaners.cleaner_name;

      Jassim XoomPage[^]

      Technology News @ www.JassimRahma.com

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      Jassim Rahma wrote:

      I want to display ALL cleaners even if no entry in the job_order table

      ..then don't use an INNER join.

      Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

      J 1 Reply Last reply
      0
      • L Lost User

        Jassim Rahma wrote:

        I want to display ALL cleaners even if no entry in the job_order table

        ..then don't use an INNER join.

        Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

        J Offline
        J Offline
        Jassim Rahma
        wrote on last edited by
        #3

        but I want to get order details as well?!

        Technology News @ www.JassimRahma.com

        L 1 Reply Last reply
        0
        • J Jassim Rahma

          but I want to get order details as well?!

          Technology News @ www.JassimRahma.com

          L Offline
          L Offline
          Lost User
          wrote on last edited by
          #4

          Jassim Rahma wrote:

          but I want to get order details as well?!

          You'd also want the cleaners that don't have an order detail?

          Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

          J 1 Reply Last reply
          0
          • L Lost User

            Jassim Rahma wrote:

            but I want to get order details as well?!

            You'd also want the cleaners that don't have an order detail?

            Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

            J Offline
            J Offline
            Jassim Rahma
            wrote on last edited by
            #5

            yes.. I want to display all if cleaner has order then it will display the SUM but if not then I want to display ZERO, null, blank or whatever..

            Technology News @ www.JassimRahma.com

            L 1 Reply Last reply
            0
            • J Jassim Rahma

              Hi, I am using the following code to populate all cleaners and display the income from every cleaner. It works fine when there is a entry for the cleaner in the job_order table but if no entry then it will not display the cleaner. I want to display ALL cleaners even if no entry in the job_order table but of course with ZERO income.

              SELECT
              cleaners.cleaner_id,
              cleaners.cleaner_name,
              cleaners.date_of_join,
              SUM(invoices.invoice_net_amount) as total_income
              FROM
              cleaners
              INNER JOIN job_orders ON job_orders.cleaner_id = cleaners.cleaner_id
              INNER JOIN invoices ON invoices.job_order_id = job_orders.job_order_id
              GROUP BY
              cleaners.cleaner_id
              ORDER BY cleaners.cleaner_name;

              Jassim XoomPage[^]

              Technology News @ www.JassimRahma.com

              B Offline
              B Offline
              Bernhard Hiller
              wrote on last edited by
              #6

              What about a LEFT JOIN?

              1 Reply Last reply
              0
              • J Jassim Rahma

                Hi, I am using the following code to populate all cleaners and display the income from every cleaner. It works fine when there is a entry for the cleaner in the job_order table but if no entry then it will not display the cleaner. I want to display ALL cleaners even if no entry in the job_order table but of course with ZERO income.

                SELECT
                cleaners.cleaner_id,
                cleaners.cleaner_name,
                cleaners.date_of_join,
                SUM(invoices.invoice_net_amount) as total_income
                FROM
                cleaners
                INNER JOIN job_orders ON job_orders.cleaner_id = cleaners.cleaner_id
                INNER JOIN invoices ON invoices.job_order_id = job_orders.job_order_id
                GROUP BY
                cleaners.cleaner_id
                ORDER BY cleaners.cleaner_name;

                Jassim XoomPage[^]

                Technology News @ www.JassimRahma.com

                D Offline
                D Offline
                David Mujica
                wrote on last edited by
                #7

                Look into LEFT OUTER joins

                1 Reply Last reply
                0
                • J Jassim Rahma

                  yes.. I want to display all if cleaner has order then it will display the SUM but if not then I want to display ZERO, null, blank or whatever..

                  Technology News @ www.JassimRahma.com

                  L Offline
                  L Offline
                  Lost User
                  wrote on last edited by
                  #8

                  Visual Representation of SQL Joins[^] :)

                  Bastard Programmer from Hell :suss: If you can't read my code, try converting it here[^]

                  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