0

I have a simple SQL query that look like this

select distinct v.col1, v.col2, v.col3
from table v
where v.col1 is not null

I would like to save the result set returned from this query into a completely new table called test.

How can I do that?

Thank you

2
  • 1
    Tag your question with the database you are using. Commented Apr 20, 2021 at 11:14
  • If i understand you, you can use SELECT .... INTO .... FROM.... But if you want up to date values try with views Commented Apr 20, 2021 at 11:15

2 Answers 2

1

you can create a view like that :

CREATE VIEW [View_name] AS
select distinct v.col1, v.col2, v.col3
from table v
where v.col1 is not null

more info about view : https://www.w3schools.com/sql/sql_view.asp

Sign up to request clarification or add additional context in comments.

Comments

0

The standard method to create a new table uses create table as:

create table new_table as
    select distinct v.col1, v.col2, v.col3
    from table v
    where v.col1 is not null;

Not all databases support this construct; for instance, SQL Server uses into:

select distinct v.col1, v.col2, v.col3
into new_table
from table v
where v.col1 is not null;

You may find that a view is sufficient, but a view is different from a table -- it is executed each time it is referenced.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.