Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Conditional Join

Status
Not open for further replies.

TonyVance

Programmer
May 4, 2007
1
US
I have two tables, task and webuser. Task has a field called repid which is an int containing the unique id for a webuser record. Webuser has two fields firstname and lastname.

I need to run a select joining task and webuser so that I get the task record and the firstname and lastname of the webuser.

The problem is I use zero as a special code for repid. I need task records that have a repid of zero to only show up once in the list, and the content of firstname and lastname does not matter. The following SQL displays records, one each for ever web user.

SELECT repid, firstname, lastname FROM task, webuser WHERE
repid=webuser.id AND task.taskdate='5/5/2007'

Any help would be appreciated.
 
As you asked in the ANSI_SQL forum, here an ANSI SQL way:
SELECT DISTINCT T.repid, W.firstname, W.lastname
FROM task T LEFT JOIN webuser W ON T.repid = W.id AND T.taskdate = DATE '2007-05-05'

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top