Solved

Using INNER JOIN, referencing fields with same name in diff tables

Posted on 2001-06-29
9
274 Views
Last Modified: 2011-10-03
I have the following SQL Statement

SELECT * FROM tblClaims INNER JOIN tblUsers ON tblClaims.fldUserID = tblUsers.fldUserID INNER JOIN tblProducts ON tblClaims.fldProductID = tblProducts.fldProductID WHERE tblClaims.fldVerified = 0

It works fine, I put it into a recordset. How do I then access fields from the different tables?

Rs("Points") - for example. What if there is a UserID in two of the tables that comes up with different values on any 1 recordset?

Ive tried Rs("tblblah.points") - but it doesn't work. How can I do this?
0
Comment
Question by:jon100
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 7

Expert Comment

by:weesiong
ID: 6237635
jon100,

Sample

Select table1.userid as userid1, table2.userid as userid2 from table1, table2

Rs("userid1")
Rs("userid2")

Good luck :)

Regards,
Wee Siong
0
 
LVL 5

Expert Comment

by:nilapenn
ID: 6237766
select * from table1,table2 where table1.fieldname=table2.fieldname

using the above query
rs.fields("Table1.fieldname").value does work prefectly for me
0
 
LVL 1

Expert Comment

by:dedsi
ID: 6237849
The fieldnames must be unique, if they are just use Rs("fieldname"). If there not you can only get one of the fields, which one it will be depends on your sql-server (though i think the order in which you write the tables make a diffrence).
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

Author Comment

by:jon100
ID: 6237870
ahh

if i run a query in sql server it shows me all of the columns (including the ones with the same field names) - I take it there is no way to get them all in 1 recordset on an asp page unless all field names are unique then?
0
 

Author Comment

by:jon100
ID: 6237885
nilapenn, it does appear to work when I use the following syntax:

Rs.Fields("tblProducts.fldPoints").value

Ill check it and get back 2u
0
 
LVL 6

Accepted Solution

by:
simonbennett earned 75 total points
ID: 6238028
...or you can alias, e.g.

Don't use * - explicitly call your fields, then when you have 2 the same, alais e.g.

Select Table1.Field1 as T1F1, Table2.Field1 as T2F1 From Table1, Table 2

...and refer to rs("T1F1")

HTH

Simon
0
 

Author Comment

by:jon100
ID: 6238087
nilapenn - for some reason I cant get it working now.

Error Type:
ADODB.Recordset (0x800A0CC1)
Item cannot be found in the collection corresponding to the requested name or ordinal.


Thanx simon - if I cant get it working the way I want i'll use your technique.

It would make sense that you should be able to do it the way I tried it though?!
0
 

Author Comment

by:jon100
ID: 6238101
nilapenn - can you give me a longer listing please.

What kind of recordset are you building etc?
0
 
LVL 7

Expert Comment

by:weesiong
ID: 6244405
jon100,

This one:
Select table1.userid as userid1, table2.userid as userid2 from table1, table2

Rs("userid1")
Rs("userid2")

And this one:
Select Table1.Field1 as T1F1, Table2.Field1 as T2F1 From Table1, Table 2

...and refer to rs("T1F1")

Got any different?

Regards,
WEe Siong

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
ASP SQL Syntax Duplicate Key 7 117
ASP Focus problem 3 72
Html Table Looping (part 2) 5 35
Asp in server side with Mssql Server 7 4 34
I recently decide that I needed a way to make my pages scream on the net.   While searching around how I can accomplish this I stumbled across a great article that stated "minimize the server requests." I got to thinking, hey, I use more than one…
This demonstration started out as a follow up to some recently posted questions on the subject of logging in: http://www.experts-exchange.com/Programming/Languages/Scripting/JavaScript/Q_28634665.html and http://www.experts-exchange.com/Programming/…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question