i am trying to INSERT into a table lets say 4 values:
- value1
- value2
- value3
- value4
all these values are stored in variables($var1, $var2, $var3..), except one of them which is part of the final value ($var4).
$var4 may return the final value4 only if with a query to another table.
$var4 stores the name of a user.
and but I want to INSERT not the user_name, but the user_id.
"user_id" is in Table "users" and i can obtain it by doing :
Expand|Select|Wrap|Line Numbers
- SELECT user_id
- FROM users
- WERE user_name = $var4
Expand|Select|Wrap|Line Numbers
- INSERT INTO some_table (var1_col, var2_col, var3_col, user_id)
-
VALUES ($var1, $var2, $var3, (
SELECT users.user_id
- FROM users
- WHERE users.user_name = $var4
- ) )
should i specify in the INSERT that the cols pertain to some_table like:
Expand|Select|Wrap|Line Numbers
- INSERT INTO some_table (some_table.var1_col, some_table.var2_col, some_table.var3_col, some_table.user_id)
-
VALUES ($var1, $var2, $var3, (
SELECT users.user_id
- FROM users
- WHERE users.user_name = $var4
- ) )
or should i first run the query to get the user_id and then make another one to INSERT?
thankyou
bilibytes