Reputation: 1587
let's say I'm Joining the Shoes
table to the Clothes
table, They both have a column called ShoesID
, so to me it would make sense to join those 2 tables on ShoesID
(it also happens to be the primary key of the Shoes
table). But here's my problem, it's not the primary key of the Clothes
table, so in the Clothes
table, in the ShoesID
column, some of the rows repeat themselves and that's ruining my join.
Is there a way to get around that?
Clothes Table ClothesID ShoesID NakedVarchar 99 |1 | e| 100 |1 | f| 101 |4 | g| 102 |4 | d| I want to join this to this: Shoes Table ShoesID Descriptionvarchar |1 | a| |2 | b| |3 | c| |4 | d|
so I figured the logical way of doing this would be to do
LEFT JOIN Clothes ON Shoes.ShoesID = Clothes.ShoesID
unfortunately because the Clothes table contains duplicates it seems Postgres cuts them out, I'd like all the data to be joined including the duplicates, how can I get around this?
it's not as simple as reversing my join statement as I'm technically trying to join them in a big query that has got many other joins.
Upvotes: 0
Views: 298
Reputation: 3759
you can make any join that you want to, even a "self-join", but if there is no coincidence or match between the keywords your query could be empty. if you want to list them all, you should use a UNION instead of a join.
Upvotes: 1