Skip to content
Advertisement

How to insert into a SQL table column using SELECT query?

I have tables A, B, and C.

enter image description here

enter image description here

enter image description here

I want to insert UserRoleName values in table C, into UserRoleName column in table A for the corresponding UserId. UserId in Table A, is a foreign key from Table B. UserRoleId is a foreign key in table B from table C. How can I do that?

I tried using this query,

But this is giving:

Cannot insert the value NULL into column ‘Z

which is a non-nullable in column A. I didn’t specify that column in picture of the table A though. Can you help me figure out what I am doing wrong?

Advertisement

Answer

You need to use update as follows:

Or using standard sql (subquery) as follows:

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement