SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    WHERE clause on JOIN query???

    I have this query:

    Code:
    $sql = "
    	SELECT unbilled_item.job_number,
    	SUM(unbilled_item.amount) AS total_unbilled,
    	job.project_manager
    	FROM unbilled_item
    	LEFT JOIN job ON (unbilled_item.job_number=job.job_number)
    	GROUP BY job.project_manager
    	ORDER BY total_unbilled DESC
    	" ;
    Is it possible to add something like:

    Code:
    WHERE user.office = "xxx"
    ???

    I can't work it out.

  2. #2
    Just Blow It bronze trophy
    DaveMaxwell's Avatar
    Join Date
    Nov 1999
    Location
    Mechanicsburg, PA
    Posts
    7,264
    Mentioned
    115 Post(s)
    Tagged
    1 Thread(s)
    You would need to add the user table to the query, of course, and you would probably need to rework the query a bit, but it should be possible....
    Dave Maxwell - Manage Your Site Team Leader
    My favorite YouTube Video! | Star Wars, Dr Suess Style
    Learn how to be ready for The Forums' Move to Discourse

  3. #3
    SitePoint Wizard Mincer's Avatar
    Join Date
    Mar 2001
    Location
    London | UK
    Posts
    1,140
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It's OK, today's query of the day is:

    Code:
    $sql = "
    	SELECT
    	SUM(unbilled_item.amount) AS total_unbilled,
    	user.office,
    	user.first_name,
    	user.surname
    	FROM job
    	LEFT JOIN unbilled_item ON (job.job_number=unbilled_item.job_number)
    	LEFT JOIN user ON (job.project_manager=user.employee_number)
    	WHERE user.office = $office
    	GROUP BY job.project_manager
    	ORDER BY total_unbilled DESC
    	" ;


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •