Insert Multiple Rows into Single Column

Insert multiple rows into single column

Another way to do this is with union:

INSERT INTO Data ( Col1 ) 
select 'hello'
union
select 'world'

SQL insert multiple rows from query result into a single column of an existing table

First, you would phrase the logic using NOT EXISTS . . . at least to simplify it. Then you would add the values for each row that you want. Then you would add the values you want using INSERT . . . SELECT:

INSERT INTO `total medals` (Country, Gold, Silver, Bronze, Total, Rank_by_Gold, Rank_By_Total)
SELECT DISTINCT a.Country, 0, 0, 0, 87, 78
FROM athletes a
WHERE NOT EXISTS (SELECT 1
FROM `total medals` tm
WHERE tm.Country = a.Country
);

MySQL: Multiple Inserts for a single column

your syntax is a bit off. put parentheses around each data "set" (meaning a single value in this case) that you are trying to insert.

INSERT INTO User_Roll(name) VALUES ('admin'), ('author'), ('mod'), ('user'), ('guest');

single Insert query to insert multiple rows in one column

We might need more information however a couple of things:

  • If you are using mysql in unix based system tables are case sensitive.
  • Second, should you use ` instead of ' on the name of your columns?(and i would say they are both innecesary) like:

    INSERT INTO tbl_Answer(`Answer`) or even better INSERT INTO tbl_Answer(Answer)

Insert multiple rows into a table with a single statement

You can have multiple inserts by not using VALUES keyword. You need to specify same number of columns on your source table.

INSERT INTO sample_tag (sample_id, tag_id) 
SELECT sample_id, tag_id from sample where sample_id<=500

How to insert multiple rows in a table with single row?

Yes (assuming you are on SQL Server 2008 or newer and don't have more than 1000 columns per row).

You can insert rows with the same schema by separating the value blocks with commas.

INSERT INTO tableA (name)
VALUES ('A'), ('B'), ('C')...

The way you're currently doing it is attempting to add each row as a column.

Insert multiple rows with single dynamic data

Simply define the correct columns in the select list:

INSERT INTO dbo.tblEmpDetails (EmpId, StateId, CountryId, Comments)
SELECT [<ReturnedColumn>], @StateId, @CountryId, @Comments
from dbo.FN_ListToTable (',', @EmpIds);

Also note that SQL Server has a built-in string_split() function.



Related Topics



Leave a reply



Submit