Skip to main content
February 22, 2008
Answered

Multiple tables with same field name

  • February 22, 2008
  • 1 reply
  • 464 views
Hi, I have a query that is pulling a field called "Total" from 20 different tables (Week1 - Week20). When I try to output the results as #Week1.Total#, for example, I get an error saying that Total is not defined in Week1. I also tried totalHours.Week1.Total (totalHours is the name of my query), but get the same thing - Week1.Total is not defined in totalHours. Please help! Thanks!
This topic has been closed for replies.
Correct answer paross1
Alias your colunms....

SELECT
request.ID, request.FirstName, request.LastName,
request.sem, request.year, request.banner,
Week1.ID AS wk1_ID, Week1.Total AS wk1_total,
Week2.ID AS wk2_ID, Week2.Total AS wk2_total,
Week3.ID AS wk3_ID, Week3.Total AS wk3_total,
Week4.ID AS wk4_ID, Week4.Total AS wk4_total....
.....etc.

They will now have different names in the output. (The table name prefix that is used in your query on each column is never displayed in the output.)

Phil

1 reply

paross1Correct answer
Participating Frequently
February 22, 2008
Alias your colunms....

SELECT
request.ID, request.FirstName, request.LastName,
request.sem, request.year, request.banner,
Week1.ID AS wk1_ID, Week1.Total AS wk1_total,
Week2.ID AS wk2_ID, Week2.Total AS wk2_total,
Week3.ID AS wk3_ID, Week3.Total AS wk3_total,
Week4.ID AS wk4_ID, Week4.Total AS wk4_total....
.....etc.

They will now have different names in the output. (The table name prefix that is used in your query on each column is never displayed in the output.)

Phil
February 22, 2008
That is seriously the best thing I have learned in a long time, thank you so much!