Before I posted this I read this too. But I thought may be my issue was slightly different.
I have a scenario where my table struct is as follows:
my_table:
my_id | what_I_have | what_I_can_do
I don't have a primary key because the table is a lookup table (nothing fundamental). All I want is to get a set of values for my_id
, which is based on certain values for what_I_have
, and what_I_can_do
. Once I get a resultset (with my_d
), I want to insert new records into my_table
for each of the my_id
in the result set with additional information for other columns.
E.g.
01001 | boxes | delivery | (existing)
01002 | boxes | delivery | (existing)
01001 | boxes | unpacking | (new)
01002 | boxes | unpacking | (new)
I have thought about doing the following:
INSERT INTO my_table(my_id, what_I_have, what_I_can_do, my_customer_company)
SELECT
my_id, 'boxes', 'unpacking'
FROM
my_table (NOLOCK)
WHERE
my_id IN (SELECT b.my_id FROM my_table b(NOLOCK)
WHERE b.what_I_have = 'boxes'
AND b.what_I_can_do = 'delivery')
I know that there might be a way to use INNER JOIN
and get this done smoothly without "nesting". But is this going to work or am I missing something here?
KR,