+ 1
Glue 2 tables side by side...
Hi guys, I came with a problem and can't find the solution. I looked on internet everywhere I could and here is the closest I found but still not right. The problem here is it cut the last part of the my longest table. The 2 tables doesn't have the same rows number but I need them all and I only need 1 category to be shown. So I need the 2 tables be glued together side by side filtered by category ( both table share the same categories ) with no missing data (of that category) So far this is what I got. I tried to join but it keep duplicating rows so instead of getting 200 rows I get like 3k rows. I tried union too and no success. I'm out of inspiration right now. https://code.sololearn.com/WIfopTvIRG1J/?ref=app
4 ответов
+ 2
Tables in a database are not really sorted right. When you do a query you get back a list but the database engine stores the data not in lists but in pretty exotic datastructures.
So when glueing things "side by side" you have to specify which element should be paired with which, and thats exactly what the `JOIN` commands do.
For easy joins that pair elements uniquely and don't duplicate rows, you want to add a new column to your table t1 which has for each row the right id of t2 to pair with.
Then you can `... JOIN table t2 ON t1.id_t2 = t2.id`.
+ 1
Yeah maybe I wrongly designed it but individually they are perfect to me anyway hehehe.
What I tried to do it similar to comparing 2 car dealers of different brand. If I want to look and compare the SUV or Sub-Compact they are not the same models except the category nothing is alike.
Hey, I tried and it doesn't work so I will work my way around :D
0
The only link the 2 tables have is the columns, each row can't be matched because they are not part of the same section.
I guess I'll do the hard work with php hehehe
thank you for your answer
0
Yeah I'm not sure what you're doing but you must've designed your tables wrong or something.
Hard to say. Whatever works for you I guess!