Unix Technical Forum

Insert based in a select

This is a discussion on Insert based in a select within the pgsql Sql forums, part of the PostgreSQL category; --> Hi list, Could someone help me with this problem I have a table like this Master table id number ...


Go Back   Unix Technical Forum > Database Server Software > PostgreSQL > pgsql Sql

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 04-19-2008, 04:08 PM
Ezequias Rodrigues da Rocha
 
Posts: n/a
Default Insert based in a select

Hi list,

Could someone help me with this problem

I have a table like this

Master table

id number
10 9898398398
20 9938378390
30 9873636736

and I want to make an insert into a table with this structure:

Secondary table

id(sequence), master_id
1 10
2 20
3 30

It is possible to make this insert based in all records of my master table ?

Any help would be very welcomed.

Best Regards
Ezequias

---------------------------(end of broadcast)---------------------------
TIP 7: You can help support the PostgreSQL project by donating at

http://www.postgresql.org/about/donate

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #2 (permalink)  
Old 04-19-2008, 04:08 PM
Phillip Smith
 
Posts: n/a
Default Re: Insert based in a select

INSERT INTO second_table (master_id) SELECT id FROM master_table ORDER
BY id;

Was it important to you that the id and master id in the second table
match up? ie, 1 and 10, 2 and 20, 3 and 30 - not 1 and 30, 2 and 10, 3
and 20 etc...

~p

On Sat, 2007-02-24 at 21:06 -0300, Ezequias Rodrigues da Rocha wrote:

> Hi list,
>
> Could someone help me with this problem
>
> I have a table like this
>
> Master table
>
> id number
> 10 9898398398
> 20 9938378390
> 30 9873636736
>
> and I want to make an insert into a table with this structure:
>
> Secondary table
>
> id(sequence), master_id
> 1 10
> 2 20
> 3 30
>
> It is possible to make this insert based in all records of my master table ?
>
> Any help would be very welcomed.
>
> Best Regards
> Ezequias
>
> ---------------------------(end of broadcast)---------------------------
> TIP 7: You can help support the PostgreSQL project by donating at
>
> http://www.postgresql.org/about/donate



*******************Confidentiality and Privilege Notice*******************

The material contained in this message is privileged and confidential to
the addressee. If you are not the addressee indicated in this message or
responsible for delivery of the message to such person, you may not copy
or deliver this message to anyone, and you should destroy it and kindly
notify the sender by reply email.

Information in this message that does not relate to the official business
of Weatherbeeta must be treated as neither given nor endorsed by Weatherbeeta.
Weatherbeeta, its employees, contractors or associates shall not be liable
for direct, indirect or consequential loss arising from transmission of this
message or any attachments

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 11:29 AM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.2.0
www.UnixAdminTalk.com