-1

Here is an insert statement.

insert into tableA (c1, c2, c3) values ( v1, v2, v3)

It happens v1 and v2 are the same value as (select x from tableB where x='y')

I want to avoid add select twice in the insert query. Is there a way like insert into tableA (c1, c2, c3) values ( (select x from tableB where x='y') a, a, v3)?

This is not a hard question but it's not a duplicate either. The difference is so obvious. Sigh. Editor. Learn to read.

CCNA
  • 388
  • 7
  • 17
  • Possible dublicate question. Please check https://stackoverflow.com/questions/25969/insert-into-values-select-from?r=SearchResults&s=4|305.1100 – Dr. X Jul 03 '19 at 02:28
  • Possible duplicate of [Insert into ... values ( SELECT ... FROM ... )](https://stackoverflow.com/questions/25969/insert-into-values-select-from) – Dr. X Jul 03 '19 at 02:29

1 Answers1

1

You seem to want insert . . . select:

insert into tableA (c1, c2, c3) 
    select x, x, 'testvalue'
    from tableB
    where x = 'y';
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786