Nati323 Posted March 30, 2015 Share Posted March 30, 2015 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 More sharing options...
justsomeguy Posted March 30, 2015 Share Posted March 30, 2015 You'll probably need to do an INSERT..SELECT. Link to comment Share on other sites More sharing options...
Nati323 Posted March 30, 2015 Author Share Posted March 30, 2015 you mean insert into select? can you give an example for this , i mean i want to do something like this: INSERT INTO tbname (col, col2) VALUES (SOMEVALUE , tbname.col * 2) you can tranlate this for me to insert into select statement? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 30, 2015 Share Posted March 30, 2015 There are some examples here:http://www.w3schools.com/sql/sql_insert_into_select.asp Link to comment Share on other sites More sharing options...
Nati323 Posted March 30, 2015 Author Share Posted March 30, 2015 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 More sharing options...
justsomeguy Posted March 30, 2015 Share Posted March 30, 2015 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 More sharing options...
Nati323 Posted March 30, 2015 Author Share Posted March 30, 2015 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 More sharing options...
justsomeguy Posted March 31, 2015 Share Posted March 31, 2015 Yeah, that should work, did you test it? I only used AS for clarity in that example. Link to comment Share on other sites More sharing options...
Nati323 Posted March 31, 2015 Author Share Posted March 31, 2015 ok, i test it, its works. thanks Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now