0

I have two tables with different data and I would like to join result in order to get data from both avoiding duplicates.

Table1:

Seasons  | Colors
win 17   | grey
win 17   | blue
win 18   | red
win 18   | black

Table2:

Seasons  | Sizes | Weights
win 17   | 48    |   8
win 17   | 47    |   7
win 17   | 48    |   5
win 17   | 47    |   9
win 18   | 42    |   2
win 18   | 43    |   3
win 18   | 42    |   4
win 18   | 43    |   1

Joining to something like :

Seasons  | Sizes | Weights | Colors
win 17   | 48    |   8    |  grey
win 17   | 47    |   7    |  grey
win 17   | 48    |   5    |  grey
win 17   | 47    |   9    |  grey
win 17   | 48    |   8    |  blue
win 17   | 47    |   7    |  blue
win 17   | 48    |   5    |  blue
win 17   | 47    |   9    |  blue
win 18   | 42    |   2    |  red
win 18   | 43    |   3    |  red
win 18   | 42    |   4    |  red
win 18   | 43    |   1    |  red
win 18   | 42    |   2    |  black
win 18   | 43    |   3    |  black
win 18   | 42    |   4    |  black
win 18   | 43    |   1    |  black

I have tried

SELECT
  Seasons,
  Sizes,
  Weights,
  Colors
FROM (SELECT
  Seasons,
  Colors
FROM Table1) c
CROSS JOIN (SELECT
  Sizes,
  Weights
FROM table2) s
WHERE c.Seasons = s.Seasons
GROUP BY Seasons,
         Colors,
         Sizes,
         Weights;

But I get duplicate colors on same season with different sizes and codes

Laxmi
  • 3,830
  • 26
  • 30
kyserslick
  • 591
  • 1
  • 10
  • 27

1 Answers1

1

TRY THIS: You can try JOIN with DISTINCT but I don't understand why you are storing data in such a way you can normalize it in better way.

SELECT DISTINCT t1.Seasons, 
    t2.Sizes,
    t2.Weights,
    t1.Colors
FROM table1 t1
INNER JOIN table2 t2 ON t1.Seasons = t2.Seasons
Shushil Bohara
  • 5,556
  • 2
  • 15
  • 32