user4329354
user4329354

Reputation:

Two different data from the same table

My tables in MySQL are the following: enter image description here

How to create a SELECT that will show: name and surname of buyer, his comment about buyed thing and name with surname of seller?

So far I've only half of it:

SELECT User.name, User.surname, Realization.comment 
FROM User, Realization, Auction, Offer 
WHERE Realization.id_vote = Auction.id_voice AND Auction.id_buyer = User.id_user AND Offer.id_offer=Auction.id_offer;

Upvotes: 1

Views: 36

Answers (1)

ScaisEdge
ScaisEdge

Reputation: 133370

You can try with a inner join

select a.name as buyer_name, a.surname  as buyer_surname, c.comment
    e.name as seller_name, e.surname as seller_surname  
from User as a 
Inner Join Auction as b on b.id_buyer = a.id_user
inner join Realization as c on c.id_voice = b.id_voice
inner join Offer as d on d.id_offer = b.id_offer 
inner join User as e on d.id_seller = e.id_user;

Upvotes: 1

Related Questions