Say I have a table, table1.
And table1 has 2 columns, "Vegetables" and "Fruits"
Using the values from table 1, how can I get the distinct of these 2 columns and use them to create a new column in a new table?
Attached is a sample table of input values, and expected output
I am using snowflake.
2
Something like this?
CREATE TABLE table2 ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(255) ); INSERT INTO table2 (name) SELECT name FROM ( SELECT vegetables AS name FROM table1 UNION SELECT fruits AS name FROM table1 ) AS names GROUP BY name;
Check this out –> sqlfiddle
SELECT DISTINCT column_name FROM ( SELECT fruits AS column_name FROM table1 UNION SELECT vegetables AS column_name FROM table2 ) AS distinct_values;
Click here to cancel reply.
2
Answers
Something like this?
Check this out –> sqlfiddle