SELECT Every Parent Table Record and INSET Multiple Record in Child Table Against the Parent_Id
0
votes
1
answer
601
views
Suppose I have two tables name company and screensavers as given below:
**Company:**
id (pk auto inc)
name (varchar)
**ScereenSavers:**
id (pk auto inc)
name (varchar)
path (varchar)
company_id (int) # This is pk of Company
Now I want to Select each company and add 3 records which means every single company's
pk
will be saved as fk
in screensaver
table for the given number of users. How can I doe this by writing something like:
SELECT id AS c_id From company
INSERT INTO screen_savers VALUES (
name='Screen Saver-I',
path='screen_save_i_path',
company_id=c_id
),(
name='Screen Saver-II',
path='screen_save_ii_path',
company_id=c_id
),(
name='Screen Saver-III',
path='screen_save_iii_path',
company_id=c_id
)
I don't know above will work, but I want to give some idea what I wanted to do. Can someone please let me know the solution?
I am using Postgresql.
Asked by Khuram
(129 rep)
May 27, 2019, 01:27 PM
Last activity: Mar 16, 2025, 08:04 AM
Last activity: Mar 16, 2025, 08:04 AM