I want to insert a row only if it exists in another table.
table thread1
id | content |
1 | Hello World |
2 | Bye World |
table thread2
id | content |
1 | Naruto |
2 | DragonBallz|
comment table
id | thread_id| thread_type | content |
1 | 1 | thread1 | hellow |
2 | 1 | thread2 | bye-bye |
Now if i do
INSERT INTO comment(thread_id,thread_type,content)VALUES('3','thread2','Whatever');
it must fail because it 3does not exist in the table thread2.
This can be checked from the thread table. But is it possible without him? No additional request?
Refresh
The tables above have been updated. thread_typerefers to the table thread1andthread2
source
share