Ask a Question related to Coldfusion Database Access, Design and Development.
-
cakesy #1
Accessing duplicate field names from different tables
Hi,
I am joining two tables, and the two tables have the same field names, but
they represent different data. eg.
table 1 - People
name - there name
title - there title (mr, dr,...)
email - email address
id - user id
table 2 - Reports
title - title of the report
date - submitted date
id - user id
When I join these two table by there user id, I want to access both the title
variables from the webpage (at the moment I am doing a select * from People,
Reports where id=id; )
I have tried searthing for this information, but can't find anything.
I also tried <cfoutput> #people.title# - and it didn't work
cakesy
cakesy Guest
-
Data Source & Duplicate Names
Hello! Please help. I?m working through a tutorial ?cfmx61_getting_started.pdf? taken from the Macromedia site. I?ve successfully set up my first... -
Looping through a structure with duplicate key names
It may be that I'm barking up the wrong tree here, and there's a nice function that will do this, but I want to turn an XML document returned to me... -
CFMX 7 Creating Duplicate Form Names
I have a cfloop that creates multiple cfforms. CFMX 7 is generating the same form name for first two forms. This prevents diffferent validations on... -
Please Help... reffering to duplicate using names in array
ok... i really need help on this one. this is what i'm trying to do. i have a MC that i duplicate on stage, and i want to refer to the duplicates'... -
How to rename Access tables and field names?
Jet SQL doesn't support any kind of rename statements directly. I figured this can probably be handled through ASP but I'm not sure how to go... -
vkunirs #2
Re: Accessing duplicate field names from differenttables
hi
when you are writing the query give the alias name for the table then it will works.
vkunirs Guest
-
cakesy #3
Re: Accessing duplicate field names from differenttables
Thanks for your reply.
I tried doing
<CFOUTPUT> #p.title#</CFOUTPUT>
but that would no work. it comes up with an error page "An error occurred when
you requested this page."
I have at the beginning of the page:
<cfquery name="Results" DATASOURCE="db">
select C.Title, C.SubEvent_id, P.FirstName, P.LastName, P.title, S.Title,
C.contribution
from Contrib C, People P, Sub S
where ....
cakesy Guest
-
Dan Bracuk #4
Re: Accessing duplicate field names from differenttables
Originally posted by: cakesy
Thanks for your reply.
I tried doing
<CFOUTPUT> #p.title#</CFOUTPUT>
but that would no work. it comes up with an error page "An error occurred when
you requested this page."
I have at the beginning of the page:
<cfquery name="Results" DATASOURCE="db">
select C.Title, C.SubEvent_id, P.FirstName, P.LastName, P.title, S.Title,
C.contribution
from Contrib C, People P, Sub S
where ....
In your select clause, give every field an alias if you qualify with a table
name or alias. In your case, that's all of them. Afterwards, refer to the
aliases.
Dan Bracuk Guest
-
paross1 #5
Re: Accessing duplicate field names from differenttables
What they are suggesting is to alias the columns with the same names in the
query so that you can use the new column name in your result:
<cfquery name="Results" DATASOURCE="db">
select C.Title,
C.SubEvent_id,
P.FirstName,
P.LastName,
P.title AS Ptitle,
S.Title AS Stitle,
C.contribution
from Contrib C, People P, Sub S
where ....
Now your fields will be Ptitle and Stitle....etc.
Phil
paross1 Guest
-
mattapple #6
Re: Accessing duplicate field names from differenttables
SELECT *
FROM People, Reports
WHERE People.id = Reports.id
mattapple Guest
-
paross1 #7
Re: Accessing duplicate field names from differenttables
mattapple,
Your suggestion isn't really helpful in this particular situation, since if
you SELECT *, which will select the columns from both tables, you will still
have two columns with the same name (title) in the output, which is what is
causing the problem in the first place. That is why it is necessary to alias
the two like named columns in order to be able to differentiate them in the
output.
Phil
paross1 Guest
-
cakesy #8
Re: Accessing duplicate field names from differenttables
Ah, excellent. This is exactly what I wanted, thanks guys. Had real trouble searching for this one.
cakesy
cakesy Guest



Reply With Quote

