RSS Forums RSS
Please support our MS SQL advertiser: Programming Forums

help with joins

Join Date: Nov 2005
Posts: 5
Reputation: stoefln is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
stoefln stoefln is offline Offline
Newbie Poster

Re: help with joins

  #2  
Nov 29th, 2005
Originally Posted by campkev
Situation

table1 has 2 columns: userid and requiredInfo
It will have an entry for every user

table2 has 2 columns: userid and optionalInfo
It will have entries for some users but not others

Problem:
need a statement that returns either

userid, table1.requiredInfo, table2.optionalInfo
--if table2 has an entry
OR
userid, table1.requiredInfo, null
--if table2 does not have an entry

can be easy done with an outher join:

SELECT table1.userid, table1.requiredInfo, table2.optionalInfo
FROM table1 LEFT OUTER JOIN table2 ON table1.userid = table2.userid
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 5:14 am.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC