SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem: same foreign keys in multiple tables

    Hi all,

    I have the same foreign keys column name in two tables. Now when I try to do a JOIN the query no longer works. I think the error message mentioned the term "ambiguous".

    Does anyone know how to fix this?

    PHP Code:
    INNER JOIN
    table 
    AS T USING (countries_id
    Thank you!

  2. #2
    SQL Consultant gold trophysilver trophybronze trophy
    r937's Avatar
    Join Date
    Jul 2002
    Location
    Toronto, Canada
    Posts
    39,215
    Mentioned
    58 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by RedBishop View Post
    Does anyone know how to fix this?
    yup... don't use USING

    instead, use ON and fully qualify both join columns, e.g.
    Code:
    FROM x JOIN y ON x.foo = y.foo
    rudy.ca | @rudydotca
    Buy my SitePoint book: Simply SQL
    "giving out my real stuffs"

  3. #3
    SitePoint Addict
    Join Date
    Jul 2013
    Location
    South of the equator, then turn left
    Posts
    360
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I suppose that might also work..


    Thanks a lot Rudy, you have been a big help


Bookmarks

Posting Permissions

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