php - Join and rename on multiple column in less queries -
i developing little site use mysql database server, i'm stuck on problem.
i have table contains user, called "user", user contain 3 columns, "username", "avatar" , "user_id"
now have second table, called "wedding", contains 6 columns: user_id of 4 different users (called mid1, mid2, tid1 , tid2), wed_id, , wed_date.
my purpose in single query (the number of queries of site limited, that's why want use minimum amount of queries) data of wedding row, , user_name , avatar of 4 user referenced in wedding, , avoid duplication, have username of first user username1, second user username2 , on, , same things avatar.
first don't know if it's possible, that's why i'm stuck on how query be, if know how create such queries i'll him lot!
select wed_id, wed_date, user1.username username1, user1.avatar avatar1, user2.username username2, user2.avatar avatar2, user3.username username3, user3.avatar avatar3, user4.username username4, user4.avatar avatar4 wedding inner join user user1 on user1.user_id = wedding.mid1 inner join user user2 on user2.user_id = wedding.mid2 inner join user user3 on user3.user_id = wedding.tid1 inner join user user4 on user4.user_id = wedding.tid2
if of foreign keys may null consider "left join" well.
Comments
Post a Comment