SQL INNER JOIN Field Namimg Conventions

This is a discussion on SQL INNER JOIN Field Namimg Conventions within the Inetserver forums in Microsoft Tools category; Ok...been working with ASP for a while and something that has always stumped me: My SQL statement is like so: SELECT * FROM tutorSessions INNER JOIN tutors On tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON tutorSessions.student_id = students.id Now, in my tutors table and my students table, I have 2 fields each with the same name, lastName and firstName. My problem is how to I reference each field in their respective tables? I've tried several things like: sql = "SELECT * FROM tutorSessions INNER JOIN tutors On tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON tutorSessions.student_id = students.id" Set RS3 = ...

Go Back   Application Development Forum > Microsoft Tools > Inetserver

Object Mix

Register FAQ Calendar Search Today's Posts Mark Forums Read
  #1  
Old 11-05-2005, 10:00 AM
ryan@jpmicro.com
Guest
 
Default SQL INNER JOIN Field Namimg Conventions

Ok...been working with ASP for a while and something that has always
stumped me:

My SQL statement is like so:

SELECT * FROM tutorSessions INNER JOIN tutors On
tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON
tutorSessions.student_id = students.id

Now, in my tutors table and my students table, I have 2 fields each
with the same name, lastName and firstName.

My problem is how to I reference each field in their respective tables?
I've tried several things like:

sql = "SELECT * FROM tutorSessions INNER JOIN tutors On
tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON
tutorSessions.student_id = students.id"
Set RS3 = Conn.Execute(sql)
response.write(RS3.Fields("students.lastName"))

Error

And the such. Thanks for the help!

Reply With Quote
  #2  
Old 11-05-2005, 10:25 AM
Bob Barrows [MVP]
Guest
 
Default Re: SQL INNER JOIN Field Namimg Conventions

ryan@jpmicro.com wrote:
> Ok...been working with ASP for a while and something that has always
> stumped me:
>
> My SQL statement is like so:
>
> SELECT * FROM tutorSessions INNER JOIN tutors On
> tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON
> tutorSessions.student_id = students.id
>
> Now, in my tutors table and my students table, I have 2 fields each
> with the same name, lastName and firstName.
>
> My problem is how to I reference each field in their respective
> tables? I've tried several things like:
>
> sql = "SELECT * FROM tutorSessions INNER JOIN tutors On


Stop using selstar.
http://www.aspfaq.com/show.asp?id=2096

> tutorSessions.provider_id = tutors.provider_id INNER JOIN students ON
> tutorSessions.student_id = students.id"
> Set RS3 = Conn.Execute(sql)
> response.write(RS3.Fields("students.lastName"))
>

The ONLY way to distinguish between them is to stop using selstar and use
column aliases to give them different names.

SELECT t.lastName as TutorLastName, t.firstName as TutorFirstName,
s.lastName as StudentLastName, s.firstName as StudentFirstName
FROM tutorSessions t INNER JOIN students s
On t.student_id = s.id

Bob Barrows
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Reply With Quote
  #3  
Old 11-05-2005, 11:41 AM
Evertjan.
Guest
 
Default Re: SQL INNER JOIN Field Namimg Conventions

Bob Barrows [MVP] wrote on 05 nov 2005 in
microsoft.public.inetserver.asp.db:

> SELECT t.lastName as TutorLastName, t.firstName as TutorFirstName,
> s.lastName as StudentLastName, s.firstName as StudentFirstName
> FROM tutorSessions t INNER JOIN students s
> On t.student_id = s.id
>


Can we do without the AS?

FROM tutorSessions t INNER JOIN students s

FROM tutorSessions AS t INNER JOIN students AS s

--
Evertjan.
The Netherlands.
(Replace all crosses with dots in my emailaddress)

Reply With Quote
  #4  
Old 11-05-2005, 11:46 AM
Bob Barrows [MVP]
Guest
 
Default Re: SQL INNER JOIN Field Namimg Conventions

Evertjan. wrote:
> Bob Barrows [MVP] wrote on 05 nov 2005 in
> microsoft.public.inetserver.asp.db:
>
>> SELECT t.lastName as TutorLastName, t.firstName as TutorFirstName,
>> s.lastName as StudentLastName, s.firstName as StudentFirstName
>> FROM tutorSessions t INNER JOIN students s
>> On t.student_id = s.id
>>

>
> Can we do without the AS?
>
> FROM tutorSessions t INNER JOIN students s
>
> FROM tutorSessions AS t INNER JOIN students AS s


Usually, the "AS" is optional. I have run into a few cases (especially in
Access) where it was required for some reason.

--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"


Reply With Quote
Reply


Thread Tools
Display Modes


All times are GMT -5. The time now is 03:38 PM.


Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
vB Ad Management by =RedTyger=

In an effort to better serve ads to our visitors, cookies are used on objectmix.com. For more information, check out our Privacy Policy.