+ 1

Help to solve the practice

Hello, I'm trying to solve the SQL practice 19.2 "What did you order?" And failing to do so. SELECT customers.fullname, customers.age, customers.address, orders.amount FROM customers RIGHT JOIN orders ON customers.id=orders.customerid; So it says: "Customers names should be outputted even if he/she doesn't have an order." and I don't understand how to do it. Can you help me out, please?

20th Sep 2021, 3:42 PM
Kakha Amashukeli
Kakha Amashukeli - avatar
5 Respuestas
+ 2
Abhay I found the solution. If we use "Right join" we should also change the order in that using "Left join". Kakha Amashukeli This is the solution buddy! You should change the order in your code. SELECT customers.fullname, customers.age, customers.address, orders.amount FROM orders RIGHT JOIN customers ON orders.customerid = customers.id;
20th Sep 2021, 4:17 PM
mesarthim
mesarthim - avatar
+ 2
I used left join. They are suggesting right join on assumption that we select orders table first.
20th Sep 2021, 4:10 PM
Abhay
Abhay - avatar
+ 1
Abhay I solved the problem as you solved. I didn't understand why it says "Use Right Join". Left is correct option I think.
20th Sep 2021, 4:14 PM
mesarthim
mesarthim - avatar
+ 1
mesarthim yes that is what i said !
20th Sep 2021, 4:19 PM
Abhay
Abhay - avatar
+ 1
Thanks all of you guys. It's solved.
20th Sep 2021, 4:20 PM
Kakha Amashukeli
Kakha Amashukeli - avatar