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. MYSQL - right join - where

MYSQL - right join - where

Scheduled Pinned Locked Moved Database
questionmysqlcomhelp
2 Posts 2 Posters 1 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.
  • N Offline
    N Offline
    nelsonpaixao
    wrote on last edited by
    #1

    Hello there guys, i trying to perform some right join to keep all records from tbl custumers, it works fine but when i do the "where" condition i noticed it killed my right join how can i solve this? i have a way to get the output i want but is very messy, so i guessed u guys could help me here, i sure is very easy X|

    select Customers.cname as c_id, sum(Products.price*Purchases.quantity) as z
    from Purchases
    right outer join Customers on (Customers.CID = Purchases.cust)
    left outer join Stores on (Stores.SID = Purchases.Stores)
    left outer join Products on (Products.SKU = Purchases.prod)
    ###where Stores.city = "Porto"
    group by Customers.cname
    order by z desc

    (my aim is to show total value of purchaces per client in some store, but i need to include all client even those that didn´t shop (zero values)) thanks

    nelsonpaixao@yahoo.com.br trying to help & get help

    M 1 Reply Last reply
    0
    • N nelsonpaixao

      Hello there guys, i trying to perform some right join to keep all records from tbl custumers, it works fine but when i do the "where" condition i noticed it killed my right join how can i solve this? i have a way to get the output i want but is very messy, so i guessed u guys could help me here, i sure is very easy X|

      select Customers.cname as c_id, sum(Products.price*Purchases.quantity) as z
      from Purchases
      right outer join Customers on (Customers.CID = Purchases.cust)
      left outer join Stores on (Stores.SID = Purchases.Stores)
      left outer join Products on (Products.SKU = Purchases.prod)
      ###where Stores.city = "Porto"
      group by Customers.cname
      order by z desc

      (my aim is to show total value of purchaces per client in some store, but i need to include all client even those that didn´t shop (zero values)) thanks

      nelsonpaixao@yahoo.com.br trying to help & get help

      M Offline
      M Offline
      Mycroft Holmes
      wrote on last edited by
      #2

      Caveat I'm a SQL Server user but would assume the syntax is similar. Put the where clause into the join

      left outer join Stores on (Stores.SID = Purchases.Stores and Stores.City = 'Porto')

      Never underestimate the power of human stupidity RAH

      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