1
I have 3 tables as follows:
At tb_usuario, I have two types of users (buyer, seller) in an ENUM field to differentiate the type of user.
In the shopping cart I have the user Ids, product and transaction number. I relate 2 times to tb_usuario to know who bought and who sold.
I want to perform a SELECT that brings the names(buyer, seller, product), but when I perform the query happens the following errors:
1 - SELECT tb_usuario.name 'buyer', tb_user.name 'seller', tb_products.name 'product' FROM purchases INNER JOIN tb_usuario ON compras.id_comprador=tb_usuario.id_usuario INNER JOIN tb_usuario ON compras.id_vendedor=tb_usuario.id_usuario INNER JOIN tb_animals ON shopping.id_product=products.id_product Where id_compra=1;
Error: #1066 - Not Unique table/alias: 'tb_usuario'
** I need to create a table for each user type due to the 2 equal aliases ?? **
Or
2 - SELECT tb_usuario.name 'buyer', tb_user.name 'seller', tb_products.name 'product' FROM purchases INNER JOIN tb_usuario ON compras.id_comprador=tb_usuario.id_usuario INNER JOIN tb_animals ON shopping.id_product=products.id_product Where id_compra=1;
Here returns twice the same name(I know it is wrong because I do not specify which is the seller).
I don’t know if it is necessary to create 3 tables or if there is a way to perform the joining 2 times of tb_usuario with the products. Could you help me
Was any of the answer helpful? Don’t forget to choose one and mark it so it can be used if someone has a similar question!
– Sorack