Defining items for WHERE in SQL | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Defining items for WHERE in SQL

SELECT customers.ID, customers.Name, orders.Name, orders.Amount FROM customers, orders WHERE customers.ID=orders.Customer_ID ORDER BY customers.ID; Above is the code from Joining Tables in the SQL course... Why does orders.Customer_ID not need to be in the SELECT as well? I completed the lesson but fear I may missed the boat on this particular section.

20th May 2019, 12:55 AM
J B
J B - avatar
3 Answers
+ 3
what you write in the SELECT is basically what you will see as result. In the FROM statement you write the parameters of your search. I’m happy I have been helpful!
20th May 2019, 2:03 AM
PacoB
PacoB - avatar
+ 3
Because you are not looking for orders.Customer_ID. You are just finding a match. The script is looking for the ID in the customers table that matches the Customer_ID in the orders table and not the customer_ID itself.
20th May 2019, 1:47 AM
PacoB
PacoB - avatar
0
Ah, ok. I was thinking of the SELECT like defining a variable. But I guess mentioning a table in FROM pulls in the whole table... That's really neat and a lot cleaner. Thanks!
20th May 2019, 2:00 AM
J B
J B - avatar