Jump to content

MYSQL JOINS ASSISTANCE


fabzster

Recommended Posts

Hi

 

I would really appreciate some assistance on the following as I suck a bit when it comes to joins

 

i have 3 tables consultants,points,orders

 

all tables have the column id_number

 

I need to run a query that will give me a list of all the consultants with a total from points and a total from orders

 

when I do a left join with 2 tables then I get the correct answer, the minute I add the 3rd I get incorrect data

 

the query:

 

SELECT

consultants.name,

consultants.surname,

consultants.cell_number,

consultants.register_status,

consultants.id_number,

Sum(points.points_added),

Sum(orders.points_cost)

FROM

consultants

Left Join points ON points.id_number = consultants.id_number

left Join orders ON orders.id_number = consultants.id_number

GROUP BY

consultants.name,

consultants.surname,

consultants.cell_number,

consultants.register_status,

consultants.id_number

 

I thing the problem lies in that some consultants do not have any orders and may not have been allocated points

 

your assistance will be greatly appreciated

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.