Wrox Programmer Forums
Classic ASP Databases Discuss using ASP 3 to work with data in databases, including ASP Database Setup issues from the old P2P forum on this specific subtopic. See also the book forum Beginning ASP.NET Databases for questions specific to that book. NOT for ASP.NET 1.0, 1.1, or 2.0.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Classic ASP Databases 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 October 15th, 2004, 05:17 AM
Friend of Wrox
Join Date: Sep 2003
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Default left join

I have 2 tables say tabA(col1,col2,col3,AdminID,cotactorid ), tabB(id,RefName)
tabA contains 5 cols out of these 5 cols ,2 cols(AdminID,cotactorid) are reffering the id field of tab B

in my sql query i want to fetch the AdminID,cotactorid and coresponding names of these 2 from tabB
my below sql giving correct refname if both adminid and contactorid are same if not its displaying null for refname.

like if adminid and contactorid are 1 its displaying
 if adminid =1 and contactorid are 2 its displaying
1,null,2 but here i want 1,"somu",2,"ramu"
how to do it.

select tabA.AdminID,tabB.RefName ,cotactorid
FROM tabA left JOIN tabB ON tabA.AdminID=tabB.idand cotactorid=tabB.id

Old October 15th, 2004, 07:12 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,998
Thanks: 0
Thanked 3 Times in 3 Posts

What table does contactorid come from?
Old October 15th, 2004, 07:37 AM
Friend of Wrox
Join Date: Jun 2003
Posts: 1,212
Thanks: 0
Thanked 1 Time in 1 Post

sounds like you need to join tabA to tabB twice, once on each id field, like this:
select tabA.AdminID, b1.RefName AS AdminName, tabA.cotactorid, b2.RefName AS cotactorName
FROM tabA left JOIN tabB b1 ON tabA.AdminID=b1.id 
          LEFT JOIN tabB b2 ON tabA.cotactorid=b2.id

Similar Threads
Thread Thread Starter Forum Replies Last Post
left outer join keyvanjan Classic ASP Basics 1 April 15th, 2006 05:37 AM
left outer join keyvanjan Classic ASP Professional 0 February 5th, 2006 11:54 AM
Why doesn't this LEFT JOIN work? harg7769 Access 2 April 13th, 2005 04:49 AM
Oracle 8i inner join and left join problem puteri_84 Oracle 2 August 19th, 2004 07:14 AM
Left Join error mariakovacs Access ASP 2 October 13th, 2003 04:16 PM

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