Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Database > SQL Language
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 24th, 2003, 03:01 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linking two tables/ Looking up data in one table

Hi,

I have two tables

REPORT - hold details about a report and who has that locked (blank if its not locked)
HR - Hold name, and id

REPORT(details,locked_by)
HR(usrid,firstname,lastname)

now if i just use

SELECT details,first_name,last_name FROM report,hr where report.locked_by = hr.usrid

it will just display those that are locked(have data in the locked_by field)

Though i need it to display the report but just have blank for the first and last name if its not in there

Any ideas? i figure this should be easy i just can't work it out

Thanks
Ash
 
Old June 24th, 2003, 03:09 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post
Default

Your "specification" isn't too clear, but it sounds like what you need is an OUTER JOIN:
Code:
SELECT details,first_name,last_name
  FROM report
  LEFT JOIN hr ON report.locked_by = hr.usrid;
This will return NULL for the 'first_name' and 'last_name' columns if there is no corresponding entry in the 'hr' table.



Jeff Mason
Custom Apps, Inc.
www.custom-apps.com
 
Old June 24th, 2003, 04:07 PM
Authorized User
 
Join Date: Jun 2003
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Thanks thats done it :O)





Similar Threads
Thread Thread Starter Forum Replies Last Post
Linking pivot tables iacon Excel VBA 3 July 24th, 2006 01:25 AM
Linking 2 data fields from 1 table aRtware Access 7 May 28th, 2006 11:23 PM
Linking Tables usedcarsgbcom Beginning PHP 4 November 23rd, 2004 08:46 PM
Prevent linking to tables MG76 Access 2 March 12th, 2004 02:29 PM
Linking Tables Con Access VBA 2 September 24th, 2003 04:32 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.