flowoverstack
flowoverstack

Reputation: 19

how to insert value and use subquery to insert the last value?

I have two tables customer and shipping_details,

customer

first_name
last_name
phone
shipping_detail_id


shipping_details

shipping_detail_id
address

where the shipping id that I need to insert has an address of 'fakeadressstreet'

The values I want to insert are 'Jackson,' mike',12345,(shipping detail id where address is = fakeadressstreet). the last value I need to insert depends on another column which is my second table no sure how to insert that value but I hope it makes sense.

Upvotes: 1

Views: 41

Answers (1)

Ergest Basha
Ergest Basha

Reputation: 9018

Something like this should work:

insert into customer ( first_name,
                       last_name,
                       phone,
                       shipping_detail_id
                     )

(SELECT   'Jackson' as first_name,
          'Mike' as last_name,
          12345 as phone,
          t1.shipping_detail_id
FROM shipping_details 
WHERE address = fakeadressstreet
) as t1 ; 

      

Upvotes: 0

Related Questions