• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Insert into two columns..help

 
Ranch Hand
Posts: 219
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic