Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Insert into two columns..help

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi.
I am stuck while doing an insert.
How do i insert value into two columns in the same table using a single insert

For Example

INSERT titles(title_id, title)
VALUES ('BU1237', 'Get Going!') where columnid='1234'

INSERT titles(title_id, title)
VALUES ('BU1237', 'Get Going!') where columnid='1235'

I need to insert the value into these two columns (columnid='1234'and columnid='1235')using a single insert.

Any suggestion on this is most welcomed.
Thanks
 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

What you are trying to do is:

INSERT titles(title_id, title)
VALUES ('BU1237', 'Get Going!') where columnid='1234' or columnid='1235'

?

Because you said:

need to insert the value into these two columns (columnid='1234'and columnid='1235')using a single insert.



But in your original query you are not doing that either.
 
meena latha
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I need to insert the same value into both the rows whose columnid is 1234 and 1235 using a single insert.

So after the insert it will look like this.

columnid titles_id title
1234 BU1237 Get Going
1235 BU1237 Get Going

i dont wat to do this using two insert,rather my single insert should insert value into these two rows.
 
Aiglee Castillo
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I need to insert the same value into both the rows whose columnid is 1234 and 1235 using a single insert.

So after the insert it will look like this.

columnid titles_id title
1234 BU1237 Get Going
1235 BU1237 Get Going



If you already have in your table the rows with columnid 1234 and 1235 then you should use:
update titles set title_id = "BU1237", title = "Get Going!" where columnid = "1234" or columnid = "1235"

Because insert will only work if you are inserting a new row, so you dont have those values in columnid. In that case you should use:
insert into titles (title_id, title, columnid) values ("BU1237","Get Going!","1234")
insert into titles (title_id, title, columnid) values ("BU1237","Get Going!","1235")

Two rows is not to much but if you need a lot more, then please give us more background about the problem.
 
Trust God, but always tether your camel... to this tiny ad.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
reply
    Bookmark Topic Watch Topic
  • New Topic