# SQL and Database: Inserting into a table where one value is the same

**URL:** <https://cog.discourse.group/t/sql-and-database-inserting-into-a-table-where-one-value-is-the-same/743>\
**Category:** useful info\
**Created:** [May 21, 2014, 2:51pm UTC](https://cog.discourse.group/t/sql-and-database-inserting-into-a-table-where-one-value-is-the-same/743 "2014-05-21T14:51:05Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Nabiki](https://sea1.discourse-cdn.com/flex001/user_avatar/cog.discourse.group/nabiki/32/935_2.png) [@Nabiki](https://cog.discourse.group/u/Nabiki)\
**Post date:** [May 21, 2014, 2:51pm UTC](https://cog.discourse.group/t/sql-and-database-inserting-into-a-table-where-one-value-is-the-same/743/1 "2014-05-21T14:51:05Z")

</div>

Okay, I’ve been trying to figure out how to do an insert into a table where one column’s value is always the same, but the second value will be from a select statement.

Something like:

```
INSERT INTO <table_name> (column1, column2)
VALUES ('055', (SELECT DISTINCT <column_name> FROM <source_table> WHERE <various conditions>)

```

The code above, obviously doesn’t work. I get an error “Subquery returned more than 1 value. This is not permitted when the subquery follows =, !=, \<, \<= , \>, \>= or when the subquery is used as an expression.”

---

<div class="post-metadata">

**Author:** ![Nabiki](https://sea1.discourse-cdn.com/flex001/user_avatar/cog.discourse.group/nabiki/32/935_2.png) [@Nabiki](https://cog.discourse.group/u/Nabiki)\
**Post date:** [May 21, 2014, 3:42pm UTC](https://cog.discourse.group/t/sql-and-database-inserting-into-a-table-where-one-value-is-the-same/743/2 "2014-05-21T15:42:12Z")

</div>

Never mind. I figured it out.

```
INSERT INTO <table_name> (column1, column2)
(SELECT DISTINCT <column_name>, '055' FROM <source_table> WHERE <various conditions>)

```

This seems to work!

---

<div class="post-metadata">

**Author:** ![dakboy](https://sea1.discourse-cdn.com/flex001/user_avatar/cog.discourse.group/dakboy/32/68_2.png) [@dakboy](https://cog.discourse.group/u/dakboy)\
**Post date:** [May 21, 2014, 3:45pm UTC](https://cog.discourse.group/t/sql-and-database-inserting-into-a-table-where-one-value-is-the-same/743/3 "2014-05-21T15:45:05Z")

</div>

Yep. In your first example, you’re attempting to insert a single record, but the `select` is returning multiple records.

In the second example, you’re inserting a set into your table - one or more records.

Watch out though, if there are triggers on your table. I think the last time I did that sort of operation, the trigger didn’t fire the way I expected. It might be a poorly-constructed trigger though.
