• 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 unique name into the table

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
i've an Emp table with empid, name, and loc columns. now, in java, query is written to insert records into Emp table from MyTable as follows:

insert into Emp (empid, name, loc) select myseq.nextval, name, loc from MyTable

in MyTable table, there are duplicate records for name column. So, those duplicate name are getting inserted into the Emp table.

how could i modify the query to insert unique name into the Emp table.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Vikas,

Please refer to the Oracle documentation for more details.

Good Luck,
Avi.
 
vikas sharmaa
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
avi, distinct can be used in simple select sql query.

here if i use, distinct as below:

insert into Emp (empid, name, loc) select myseq.nextval, distinct name, loc from MyTable

it will give sql error.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You use distinct after "select." If you want the names to be unique (which is probably incorrect; there will be people with the same name as each other), you need to
  • Label the column UNIQUE when you create the table or
  • Use an ALTER TABLE names MODIFY COLUMN . . . instruction.
  •  
    Consider Paul's rocket mass heater.
    reply
      Bookmark Topic Watch Topic
    • New Topic