Answer the question
In order to leave comments, you need to log in
Where to practice complex JOIN queries?
I came to work with a highload project with my knowledge of the level of one INNER JOIN which is used to connect with some table. While I'm June, I'm studying, but in the project I see queries where four joins flash, it's even more strange when the same table is joined 3 times, for the same field, but with different values (for example, how would it be INNER JOIN users as us1 ON us1.age = 18 INNER JOIN users as us2 ON us2.age = 20)
I don’t understand the point of joining the same table 3 times, and I don’t really see the point of setting different values either, I just can’t understand what is written here.
Actually, how to practice in joins? (on a serious note, not where one join)
Answer the question
In order to leave comments, you need to log in
Esteem once again the theory about JOIN and about the third normal form and still esteem what such ONE TO MANY (one to many) and MANY TO MANY (many to many).
Suppose you have one large PRODUCTS table and it looks like this:
ID ITEM_ID NAME PRICE COMMENTS and it so happened that one product can have a lot of comments, several prices and several names, then you will need to do additional for each option. a row in the table, for example
1 31337 Table 10.00 I like my table
2 31337 Table 10.00 What a cool table
To avoid repetition, normal forms were invented and now we already have several tables:
PRODUCTS, COMMENTS, PRICES, NAMES
In the table there are only product IDs, in comments product ID and comments, in prices only product ID and price, in titles product ID and name. What we have done is called database normalization.
TOTAL
now, to get all the data about one product, you can JOIN four tables by product ID or make a query with where on four tables.
In reality, there are cases when database normalization is not needed for the sake of performance.
practice here to
find out how JOIN differs from WHERE IN - here
Actually, you already have a place to practice,
practice at work, look at the database, tables,
what data is in the table.
start with simple queries, then more difficult, and so on.
you can raise a server on your machine and torment it with requests, now using docker this is done on 1-2-3
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question