Jump to content

insert into table column from another table


Nati323
 Share

Recommended Posts

hey i have a big query that i insert with her data, now i want to insert to one column the value of another column from another table and to multiply this with some value i have, i try to do something like this:

INSERT INTO tbname (sal) VALUES (another_table.column * 5)

but the result is:

Unknown column 'employees.salary' in 'field list'

 

maybe its possible with insert into select, but i dont know how to combine this with other columns that i want to insert...

 

thanks for your help !

Link to comment
Share on other sites

yes, i read this , i know how to do a normal insert into select statement,

what i dont know is how i combine this with other values that i want to insert,

what i mean that only one column need to inserted from the other table, the rest column get values from the php script.

there is no example for this in the tutorial...

Link to comment
Share on other sites

You can use specific values in a select statement, you don't need to only select columns.

SELECT 'some text' AS `text_string`, 10 + 5 AS `fifteen` ...
You don't need to give the columns names if you're using the select in an insert query.
Link to comment
Share on other sites

sorry i dont understand,

first why you use AS?

second, for example i want to insert to my table to column 'a' the value 3, and to column 'b' the value of TABLE_2.SOME_COL , so i do like this ? :

INSERT INTO tbname_1 b, aSELECT SOME_COL, 3 FROM TB_2

if you understand what i mean, i want to insert some values that they are not from the selected table...

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...