Accessing duplicate field names from different tables

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default 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

  2. Similar Questions and Discussions

    1. 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...
    2. 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...
    3. 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...
    4. 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'...
    5. 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...
  3. #2

    Default 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

  4. #3

    Default 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

  5. #4

    Default 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

  6. #5

    Default 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

  7. #6

    Default Re: Accessing duplicate field names from differenttables

    SELECT *
    FROM People, Reports
    WHERE People.id = Reports.id
    mattapple Guest

  8. #7

    Default 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

  9. #8

    Default 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

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139