Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases

Blake Leal
Blake Leal
6,237 Points

SQL Basics - Challenge 1 -- Create a list of mailing information for orders that took place on April 20th, 2017.

I found this question too open-ended, but it forced me to be creative.

Q: -- Create a list of mailing information for orders that took place on April 20th, 2017.

My Logic:

select * from sales where sale_date = "2017-04-20"; --Returned nothing...

select * from sales where sale_date != "2017-04-20"; --Returned data, including 2017-4-20

select * from sales where sale_date = "2017-4-20"; -- Returned sales from customers on the requested date.

select * from sales, customers where sales.id = customers.id and sales.sale_date = "2017-4-20"; -- This will give me all the data for the return above. Now filter for ONLY mailing data, which would need the name of the recipient to address the mail.

select first_name, last_name, delivery_address from sales, customers where sales.id = customers.id and sales.sale_date = "2017-4-20"; -- Solution.

Am I answering the wrong thing with my queries? The solution provided was simple, but I felt that in real-world applications, that little data wouldn't suffice, hence the deeper dive.

1 Answer

Rohald van Merode
seal-mask
STAFF
.a{fill-rule:evenodd;}techdegree
Rohald van Merode
Treehouse Staff

Hey Blake Leal 👋

I don't think you're necessarily answering the wrong thing with your queries, and as Andrew states in the videos there are often multiple ways to accomplish the same thing. 🙂

That being said though, I do notice one issue in the queries you've written as the names are not lining up with the sales. You're currently comparing the sales.id to the customers.id but those id's are not associated with each other. It's not a given that customer with the id of 1 is also the person that placed the order with sale id 1. For these kind of associates you'd need a relationship set up across the two tables which is not the case in the provided tables.

Because of this the name for the second sale for example is showing Jonathan Luna while looking at the data in the sales table the customer_name for that order is Andrew Chalkey.

Hope this helps!