943,948 Members | Top Members by Rank

Ad:
  • MySQL Discussion Thread
  • Unsolved
  • Views: 693
  • MySQL RSS
Dec 19th, 2008
0

Mysql Join help

Expand Post »
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

MySQL Syntax (Toggle Plain Text)
  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
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
fabzster is offline Offline
30 posts
since Aug 2007
Dec 19th, 2008
0

Re: Mysql Join help

Try this

MySQL Syntax (Toggle Plain Text)
  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
Reputation Points: 22
Solved Threads: 9
Junior Poster in Training
varmadba is offline Offline
83 posts
since Jun 2008

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in MySQL Forum Timeline: error:when special characters are inserted
Next Thread in MySQL Forum Timeline: Display mysql data





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC