How to create new table from a distinct table in sql? [duplicate]

i currently have a table named my_table, like:

enter image description here

now when i run this query:

SELECT DISTINCT Country,Zipcode,Plan_Id FROM my_table;

it's gives me a table without those repeated rows. now i want that output in a new table, how do i do?

1

1 Answer

You need CREATE TABLE . . SELECT :

CREATE TABLE table
AS SELECT DISTINCT Country, Zipcode, Plan_Id FROM my_table;

By this way you will get data into new table. If you already have a new table then use INSERT INTO . . . SELECT instead :

INSERT INTO table (Country, Zipcode, Plan_Id) SELECT DISTINCT Country, Zipcode, Plan_Id FROM my_table;

You Might Also Like