1

i am trying to insert into my sql table a combination of php variables and 1 row data from another table. ive found examples that are similar but none that have this combination.

OTHERTABLE.liveDate would be where i need the single record from, but i would need to add a condition such as WHERE id='1' from OTHERTABLE

'$navid', '$loginid', '$total', '$where' are not from OTHERTABLE

INSERT INTO myTable (`navid`,`loginid`, `pageDisplayNum`, `whereFrom`, `liveDate`) 
VALUES ('$navid', '$loginid', '$total', '$where', 'OTHERTABLE.liveDate')

1 Answer 1

2
INSERT INTO myTable (`navid`,`loginid`, `pageDisplayNum`, `whereFrom`, `liveDate`) 
select '$navid', '$loginid', '$total', '$where', OTHERTABLE.liveDate 
from OTHERTABLE
where OTHERTABLE.id='1'
Sign up to request clarification or add additional context in comments.

2 Comments

+1 I did not know you can do this. I always inserted a foreign key. What are the pro/cons of the answer vs using a foreign key?
thank you for the response, i've edited my question. '$navid', '$loginid', '$total', '$where' are not from OTHERTABLE

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.