Mysql Join help

Reply

Join Date: Aug 2007
Posts: 10
Reputation: fabzster is an unknown quantity at this point 
Solved Threads: 0
fabzster fabzster is offline Offline
Newbie Poster

Mysql Join help

 
0
  #1
Dec 19th, 2008
Hi

Im not sure if i need a join here, i cant seem to grasp the concept of joins really batteling with this

I allocate points to id numbers in the points table and i have a list of all id numbers in the consultants table

the id numbers only exist in the points table if points where allocated to them

I would like to be able to see what consultants did not earn any points in a specific date range eg a month. so I would like a list of all the missing Id numbers in the points table for a specific month

  1. SELECT consultants.name
  2. , consultants.surname
  3. , consultants.cell_number
  4. , consultants.id_number
  5. FROM consultants
  6. LEFT OUTER
  7. JOIN ( SELECT id_number
  8. FROM points WHERE date_added BETWEEN '2008-01-01' AND '2008-01-30'
  9. GROUP
  10. BY id_number ) as pts
  11. ON pts.id_number = consultants.id_number

this only shows me the consultants that have points in the month

I would really appreciate some help
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 79
Reputation: varmadba is an unknown quantity at this point 
Solved Threads: 8
varmadba varmadba is offline Offline
Junior Poster in Training

Re: Mysql Join help

 
0
  #2
Dec 19th, 2008
Try this

  1. SELECT consultants.name
  2. , consultants.surname
  3. , consultants.cell_number
  4. , consultants.id_number
  5. ,points.id_number
  6. FROM consultants
  7. LEFT OUTER JOIN points
  8. on points.id_number = consultants.id_number
  9. AND date_added BETWEEN '2008-01-01' AND '2008-01-30'
  10. HAVING points.id_number IS NULL
:- Varma

We are Happy to inform launch of a new site with loads of database related information Site offers wide range of functionality Forums,Blogs,Articles,Editorials and much more
http://www.sqllibrarian.info/
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC