Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Database > SQL Language
Password Reminder
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old June 24th, 2003, 03:01 PM
Authorized User
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts
Default Linking two tables/ Looking up data in one table


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


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

Reply With Quote
  #2 (permalink)  
Old June 24th, 2003, 03:09 PM
Friend of Wrox
Join Date: Jun 2003
Location: Hudson, MA, USA.
Posts: 839
Thanks: 0
Thanked 1 Time in 1 Post

Your "specification" isn't too clear, but it sounds like what you need is an OUTER JOIN:
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.
Reply With Quote
  #3 (permalink)  
Old June 24th, 2003, 04:07 PM
Authorized User
Join Date: Jun 2003
Location: , , .
Posts: 15
Thanks: 0
Thanked 0 Times in 0 Posts

Thanks thats done it :O)
Reply With Quote

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 Off
Pingbacks are On
Refbacks are Off

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

All times are GMT -4. The time now is 02:25 PM.

Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.