I'm not completely sure I understand you but:-

select * from Jobs left outer join Users on Jobs.JobID=Users.JobID;

Should give all the jobs, with null user data where there isn't a 
user associated with a job.

Jon

> Hiya all,
> 
> I have (for illustration purposes) two tables in an ODBC database:
>  Table 'Jobs'=JobID,JobDescription,JobDate
>  Table 'Users'=UserName,JobID,LastViewedDate
> 
> Basically I want to select all JobID's and JobDescriptions from Jobs
> where the user has a 'lastvieweddate' within the last 10 days.
> 
> That bit I can work out - the problem is, is if there isn't an entry
> in the 'Users' table for a particular JobID. I could include nulls for
> the UserName for each jobid in the Users table and have an SQL statement in
> the format:
>  ...AND (Users.UserName='' OR Users.UserName='John Doe')...
> 
> But that may give me two records - which I don't really want. I could
> temporarily store the duplicates in a Perl array or hash and remove
> duplicates that way, but I would prefer a 'pure' SQL solution.
> 
> Therefore, the question is:
>  * Is there any way of SELECTing Jobs.JobID, Jobs.JobDescription, and
>    Jobs.JobDate with Users.LastViewedDate if the UserName is found in
>    the Users table complete with the corresponding JobID. If there
>    isn't a Users.UserName.Users.JobID=Jobs.JobID entry, still return
>    the Jobs.JobID, Jobs.JobDescription and Jobs.JobDate details.
> 
> Many thanks,
> Richy C.
> [speaking personally]
> --
> Richard Chiswell, Systems Developer.
> Cradley Print Group.
> All opinions and comments expressed are NOT necessarily those of the Cradley
> Print.
> 
> 
> -- 
> The information contained within this e-mail sent by Cradley Print Ltd. is
> confidential and is intended for the named recipient only. If you are not
> the intended recipient please notify us by telephone immediately on 01384
> 414100 (UK)or +(44)1384 414100 (International) or return it to us by e-mail
> quoting the name of the sender and the addressee. Please then delete it from
> your system.
> 
> Encryption and Viruses
> ==================
> Please note that this e-mail and any attachments have not been encrypted.
> They may therefore be liable to be compromised. Please also note that it is
> your responsibility to scan this e-mail and any attachments for viruses.
> Viruses and compromises of security are inherent risks in relation to
> e-mail.
> 
> We do not, to the extent permitted by law, accept any liability (whether in
> contract, negligence or otherwise) for any virus infection and/or external
> compromise of security and/or confidentiality in relation to transmissions
> sent by e-mail.
> 
> Contracts
> ========
> Please note, that contracts may NOT be concluded on behalf of Cradley Print 
> Ltd by e-mail, but contracts on behalf of our clients may be concluded by 
> e-mail.
> 


Reply via email to