r/learnSQL • u/younesWh • Jul 23 '26
two relations for one column
does it possible to give a column choice to choose between two foreign keys
the case: that I Have comments table that have a parent_id column that could be either from posts table or comments table how I can implment that in sqlite3 .
3
Upvotes
View all comments
Show parent comment
1
u/younesWh Jul 24 '26
I dont think I will have provlem while query and entity(comment or post ) comments.. But the problem is inserting while avoid atatching to unexist parent...so Instaed of using Fk what about chekc if oarent id existine either table using EXISTS