Posts

Showing posts with the label left-join

Inner joining multiple columns to one ID [duplicate]

Inner joining multiple columns to one ID [duplicate] This question already has an answer here: I'm not in charge of the database so I can't change the format, I realize it is a horrible database. I have two tables I want to join: Table1: address_book id | name | address | phone number | email Table2: team id | person1_id | person2_id | person3_id | person4_id | person5_id | person6_id I would like to join all the personX_id with the name from address_book. I can't seem to figure out how to join more than one column. Hoping someone here could help! Thanks This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question. 1 Answer 1 if you have only 6 colums for person_id you could use a multiple join select a1.name from team t left join address_book a1 on a1.name = t.person1_id left join address_book a2...

LEFT JOIN - Return empty results with left join for sum of payment_method

LEFT JOIN - Return empty results with left join for sum of payment_method This is my first question on stackoverflow so I try my best to not screw up. I am scratching my head on this query for a couple of hours and can't make any progress. I use a view which has several bookings in it. All those bookings have a payment_method e.g. paypal or creditcard. Customer Name | Price | payment_method John Doe | 20 | creditcard Susan Soe | 10 | paypal With my sql query I am trying to get the sums for all payment_methods. Unfortunately payment_methods which were not used this month don't show up. So I created an additional table called PaymentMethods with the column Methods. Methods creditcard premium sofort bank paypal I then tried to use a LEFT JOIN to get a result like this: LEFT JOIN payment_method | TotalQuantity (->sum(price)) creditcard | 20 premium | 0 sofort | 0 bank | 0 paypal | 10 But instead I only get those sums r...