2

I have created 3 tables.

  • books (id, name, author, edition, status, quantitity, department, category)
  • issued_book (username, book_id, status, issue_date, return_date)
  • users (id, postition, fristname, lastname, username,email, contat, password)

I get this error when executed the following query.

#1052 - Column 'status' in field list is ambiguous

Query:

SELECT users.username
     ,position
     ,books.id
     ,name
     ,author
     ,edition
     ,status 
  FROM users 
  join issued_books 
    ON users.username = issued_books.username   
  join books 
    ON issued_books.book_id = books.id 
 WHERE issued_books.status =''

Can someone provide me with the executable query?

2 Answers2

0

You should use alias like below:

SELECT 
u.username,
u.position, 
b.id,
b.name,
b.author, 
b.edition,
b.status 
FROM users u 
inner join issued_books i ON u.username=i.username 
inner join books b ON i.book_id=b.id WHERE i.status =''

Akhilesh Mishra
  • 5,876
  • 3
  • 16
  • 32
0
SELECT u.username, u.position, b.id, b.name, b.author, b.edition, b.status 
FROM users u 
INNER JOIN issued_books ib ON u.username=ib.username 
INNER JOIN books b ON ib.book_id=b.id WHERE ib.status =''
Red Black
  • 13
  • 3
  • While this code may answer the question, providing additional context regarding how and/or why it solves the problem would improve the answer's long-term value. – Donald Duck Jan 13 '21 at 12:31