Ad

NEED HELP **triggers With Join**

- 1 answer

two tables

users

  • user_id , username , password , email

posts

  • user_id , post_id , post

i want to join these two tables by user_id and create new table

posts_join

  • user_id , username , post

but now i dont know how to make trigger of this problem i want to update post_join when there is an insertion in posts table

Ad

Answer

The posts_join table is duplicating the function of the foreign key in the posts table.

Remove the posts_join table from your database and replace it with a view:

create view posts_join
as
select  u.user_id
,       username
,       post
from    posts p 
join    users u
on      u.user_id = p.user_id
Ad
source: stackoverflow.com
Ad