Last week, we had the author of TDD for a Shopping Website LiveProject. Friday at 11am Ranch time, Steven Solomon will be hosting a live TDD session just for us. See for the agenda and registration link
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

i want query for inserting two input parameters and remaining fields from other table in single quer

 
Ranch Hand
Posts: 237
MyEclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i want query for inserting two input parameters and remaining fields from other table in single query.
example :
INSERT INTO Members ( memberName, userID)
VALUES('MYNAME', (SELECT userID FROM USERS WHERE userUNIQUEID = '123'));

i need to insert a row into member table.
i want to pass 'MYNAME' as parameter and UserId will be from select statement.

can any one please give me correct syntax of the query.
 
Sheriff
Posts: 3837
66
Netbeans IDE Oracle Firefox Browser
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This should work:
Add as many constants to the SELECT clause as you need (number of values in the SELECT clause must match the number of columns being inserted, of course).

Two notes:

Is userUNIQUEID really a VARCHAR? If it is a NUMBER, you should use 123 and not '123'.

If you plan to run this statement from Java, use PreparedStatement and replace literal values with binds.
 
sudheer kiran
Ranch Hand
Posts: 237
MyEclipse IDE Firefox Browser Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi thank you for the reply.
that was a example query.

i have found the solution
i need to give my parameter value in select clause.
INSERT INTO Members ( userID,memberName) SELECT userID,'MYNAME' FROM USERS WHERE userUNIQUEID = '123';

thank you.
 
You get good luck from rubbing the belly of a tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic