Search code examples
sqldistinct

How to get the distinct values in PieCloudDB Database?


I have a table in my PieCloudDB database that has two columns:"vegetable" and "fruit". There are some redundant data. How can I get the distinct data and merge them in one column?

Vegetable Fruit
carrot cherry
carrot apple
cabbage peach
mushroom cherry
pepper orange
pepper strawberry
Distinct_Column
peach
carrot
cabbage
pepper
mushroom
strawberry
cheery
orange
apple

Solution

  • Try this will give the results you want:

    SELECT distinct_column FROM
    (
      SELECT fruit AS distinct_column FROM PieCloudDB
      UNION
      SELECT vegetable AS distinct_column FROM PieCloudDB
    ) AS distinct_values;