So in our last video, we talked about the idea of understanding your data so that you're writing queries that will help you answer your questions. We're going to continue that discussion here. Part of what you'll do when you're trying to understand your data is you'll start to profile your data. This is where you do descriptive statistics. It's also a good opportunity to identify any data quality issues before really diving into your analysis. It's always a good idea to take this profiling step before you finalize any of the data you're extracting. We're going to talk about those steps in this video. After this lesson, you should be able to determine and map out the data elements needed for a query. Discuss some of the strategies to employ, as you'd begin to write more complex queries. And explain some common troubleshooting techniques to try in your SQL code when it isn't giving you the results you expect. Okay, so to really understand a problem, you really need to map out what are the exact data elements you need. You need to know the data you're going to go after and understand some of the issues with the data from the profiling you've done. So where do you start with your data and query? If you're always extracting data, it's always going to start with the select statement. So you're going to have to use select and from. What I do is usually write out okay, where is the data that I need? And then kind of draw out a diagram of the different tables and the pieces of information I need on paper. Basically, just creating my own data model and map. I start with this just as sources, and then from each source, I go down and define the fields I need. And then from there, I also define how I'm going to join those different sources together. From that point, I'm going to decide if I need to do any calculations. It's just kind of going through a logical process that I go through. But again, you're always going to start with SELECT. I mean that's the great thing about SQL, it's consistent in that way. What I recommend is to start simple, especially if you're new to the data. Start with just one table, add in more data, add in another table, check your results and then go back from there. If you're using sub queries, remember to always start with the innermost query and then work out and build. Start small. That leads us to our next tip which is test along the way. Don't wait to test your query until you've combined multiple sources together. And you have all your calculations done and finished. Think of this as little building blocks. If you write a calculation of the average selling price of something, look at how many values you're getting back for just that calculation from the table and make sure that seems right. Then combine this result with another table and then test that. If you know your data, you could dive in a little bit quicker. But this will really make sure that your order of operations is correct. This is key because as I have said before, it's easy to get results back but getting the right results back that you expect is a little bit harder. Okay, let's talk about troubleshooting. When troubleshooting, it's important to always start small and simple, and slowly start to rebuild the query to see where things went awry. It's helpful to start at the basic things first. Okay, I'm getting these fields from this table. Does that work? Yes, okay, now I'm getting these fields from this table and from another table. What's my join like? Is this working? Okay, yes it is. Slowly start to build it back up in order to figure out where things went wrong. Let's say at this point, you're working through a problem and you know your data you have profiled it, you've tested it, and you have started simple and you have your query. Be sure that when you are writing it, the next thing to look at is to make sure you are formatting it correctly and commenting nicely. I think that clean code says a lot about you. Make sure that it's easy to read, you're using popular indentation, you're commenting strategically where you need to, etc. You never know when you're going to need to revisit your query or you're going to need to hand it in to someone else and they need to edit to, from there. Just keep your code clean. Format your comments where necessary and strategically. Then, you want to make sure to review what you've done. A lot of times, what happens is you'll write a query, you'll be using it for your model, and you'll be looking at different stats and things like that. Then you need to go back and edit and change that query. Always make sure you review the query to see if anything has changed. Has the data changed? Are the business rules different? Do you need to update and change the date indicators? Does anything need to be updated? And general, be really careful when you're going back and using old queries. Okay, that really takes you through a problem from beginning to end. Again, it all starts with the data and problem understanding. Make sure you spend the time there. Make sure you are really spending the time thinking about what you are doing before you actually start writing the queries. I promise, it will save you time in the long run, then go through and really understand your data through profiling it. Make sure you're testing along the way, and keeping your code clean and commenting. Those are just a few little tips that I can give you. You're fully equipped now to go and retrieve the data you need, which is exciting because the first step in doing data science is to be able to get your data. You now have that in your toolbox. Reflect on these steps and framework when you look at problems and start writing your queries. All right, go and get your data and start analyzing in.