Search code examples
sqldistinctselect-into

SQL Select Into Field


I want to accomplish something of the following:

Select DISTINCT(tableA.column) INTO tableB.column FROM tableA

The goal would be to select a distinct data set and then insert that data into a specific column of a new table.


Solution

  • You're pretty much there.

    SELECT DISTINCT column INTO tableB FROM tableA
    

    It's going to insert into whatever column(s) are specified in the select list, so you would need to alias your select values if you need to insert into columns of tableB that aren't in tableA.

    SELECT INTO