Search code examples
mysqlsqldatabaseleft-joininner-join

I cannot get my joins to work on a some tables, but they will work on others. Trying to select columns from 2 tables


ERD

I am new to mySQL so sorry for the basic question, When I try to join my rental table and tp_rental table via the 'Rental_ID' column I get errors saying Error code: 1052 Column 'Rental_ID' in field list is ambiguous.

i can join rental and member tables no problem.

i am trying to print out a transaction report when a rental is completed (game is returned) that it will show rental ID, memberID, Due Date and Date Returned. I was using the below code but getting errors:

select Rental_ID,member_ID,completed,Date_Due,Date_Returned
from gamestoredb.rental
inner join gamestoredb.tp_rental
on rental.Rental_ID=tp_rental.Rental_ID

Solution

  • Rental_ID is a column in each of the two tables you are joining so the server does not know which one you want rental.Rental_ID or tp_rental.Rental_ID even though in this particular they both would have the same value. Make which one you want explicit, for example:

    select tp_rental.Rental_ID,member_ID,completed,Date_Due,Date_Returned
    from gamestoredb.rental
    inner join gamestoredb.tp_rental
    on rental.Rental_ID=tp_rental.Rental_ID