Artur-M Artur-M - 2 years ago 85
SQL Question

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.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;

Answer Source

You can try with a inner join

select as buyer_name, a.surname  as buyer_surname, c.comment 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;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download