sql joins and getting used to them [closed]
开发者_StackOverflow
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this questionI had a big interview that I screwed up when the interviewer asked me to join three tables. I can verbally describe the different types of joins, but I froze up. I'm looking for something that gets me used to these types of problems so I can anticipate how to solve them. Anybody have any SQL excercises they could possibly recommend?
I'll start with a couple:
Jeff's A Visual Explanation of SQL Joins
SQL JOIN - SQL Tutorial
Understanding SQL Joins
I would install MySQL or any other free SQL database, and just go through some examples. Best way to remember things is by having done them with repetition. Also, seeing actual data results always helps to visualize what the different functions do. I know MySQL offers lots of webinars, that might be a good place to start?
MySQL Webinars
You might try to create a database with three tables, such that you would need to take joins on all of them to get used to multiple joins. One example:
User(user_id, name,email) has_many Cars(car_id, car_name, car_model_id), and Car has_one Model(model_name, model_id, year_of_model) etc, and then try to answer a few questions like:
- how many cars does a user A have, and what are their models
- how many distinct models of cars does a user A have
etc etc. Such small exercises can help you get started, so that you can think comfortably about models, joins, and relattions etc. (The example is probably not complete as I havent specified the other direction of the relation, but you can do that yourself. for example, a user has_many cars, and a car has_one user, and a car has_one model and a model has_many cars.)
精彩评论