All we need is an easy explanation of the problem, so here it is.
I wanna add some data into two columns in a table.
Would be something like:
INSERT INTO dm.billables_links (billable_id) VALUES ((SELECT billable_id FROM junk.wm_260_billables2 WHERE info ilike '%Ali%')),
INSERT INTO dm.billables_links (mobiuser_id) VALUES ((SELECT id FROM public.ja_mobiusers WHERE name_first LIKE 'Ali%' AND name_last LIKE 'Daon%'))
Question:
Note that the “billable_id” selected on the first INSERT must be related to the “mobiuser_id” selected on the second INSERT.
How can I do such a thing?
Table dm.billables.links columns:
billable_id, mobiuser_id
SELECT id FROM public.ja_mobiusers WHERE name_first LIKE 'Ali%' AND name_last LIKE 'Daon%'
950898
SELECT billable_id FROM junk.wm_260_billables2 WHERE info ilike '%Ali%'
13270372
How to solve :
I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.
Method 1
Fast and dirty:
INSERT INTO dm.billables_links (billable_id,mobiuser_id) VALUES (
(SELECT billable_id FROM dm.billables WHERE account_id = 32152
AND billable_id IN (select billable_id from junk.billable_id),
(SELECT id FROM public.ja_mobiusers WHERE name_first LIKE 'Alisha%'));
or a JOIN, if an relation between “billable_id”(junk.billable_id) and “id”(public.ja_mobiusers) exists.
Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂
All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0