shervin - shervin - - 2 months ago 6
SQL Question

Insert into one column by selecting another column in other table but how fill the second column

i have a table which has two columns i'd fill one of the columns by selecting other table column data but how can i fill the next column cause i can't use VALUE. Here's the code

INSERT INTO Numbers(number, val) SELECT LaptopID FROM Laptop WHERE Laptop.Pid = 2


as you can see the "val" column left empty how can i fill that?

aF. aF.
Answer

Use NULL if the column allows it:

INSERT INTO Numbers(number, val)
SELECT LaptopID, NULL
FROM Laptop WHERE Laptop.Pid = 2

Or use the intended (hardcoded) value that you want.

If number:

INSERT INTO Numbers(number, val)
SELECT LaptopID, 2
FROM Laptop WHERE Laptop.Pid = 2

or if text:

INSERT INTO Numbers(number, val)
SELECT LaptopID, 'val'
FROM Laptop WHERE Laptop.Pid = 2
Comments