If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > MySQL > How to Join this query?

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-22-06, 10:10
GoMo GoMo is offline
Registered User
 
Join Date: Nov 2003
Location: London, UK
Posts: 39
How to Join this query?

I'm trying to join two tables:

Code:
tbl_role                         tbl_project_role
id  role        rate-default     id  project-id  role-id  rate-override
1   Manager     100.00           1   4           1        80.00
2   Programmer  40.00            2   5           1        90.00
3   Designer    50.00            3   4           2        45.00
                                 4   6           3        45.00
So now I'm trying to find the rates for all the roles for any given project, say project #4. I would like the results in the following format.

Code:
role-id  role        rate-default  project-role-id  project-id  rate-override
1        Manager     100.00        1                4           80.00
2        Programmer  40.00         3                4           45.00
3        Designer    50.00         NULL             NULL        NULL
I'm just not sure how to construct this query, any ideas?

Thanks.
Reply With Quote
  #2 (permalink)  
Old 06-22-06, 10:17
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
select r.id    as role_id  
     , r.role        
     , r.rate_default
     , pr.id   as project_role_id
     , pr.project_id
     , pr.rate_override
  from tbl_role as r
left outer
  join tbl_project_role as pr
    on pr.role_id = r.id
   and pr.project_id = 4
__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 06-22-06, 10:36
GoMo GoMo is offline
Registered User
 
Join Date: Nov 2003
Location: London, UK
Posts: 39
Thanks, I didn't realise you could AND on joins
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On