robertohuertasm / SQLite4Unity3d

SQLite made easy for Unity3d
MIT License
1.27k stars 265 forks source link

Many to Many relationships #110

Closed devotionsolutions closed 3 years ago

devotionsolutions commented 3 years ago

What's the proper way to deal with many to many relationships between tables using this library? Let's say we have three tables:

Like in this diagram

Any idea?

afandiyusuf commented 3 years ago

You always can use manual queries with this library.

Select * from categories right join categories_subcategoris on categories.id = categories_subcategories.categories_id left join sub_categories on categories_subcategories.subcategories_id = subcategories.id

devotionsolutions commented 3 years ago

You always can use manual queries with this library.

Select * from categories right join categories_subcategoris on categories.id = categories_subcategories.categories_id left join sub_categories on categories_subcategories.subcategories_id = subcategories.id

Great idea, but unfortunately "RIGHT and FULL OUTER JOINs are not currently supported" for sqlite

afandiyusuf commented 3 years ago

You could emulate RIGHT JOIN with LEFT JOIN by swapping the position table when selecting it.

Select * from categories_subcategoris left join categories on categories.id = categories_subcategories.categories_id left join sub_categories on categories_subcategories.subcategories_id = subcategories.id

Hope it help.

devotionsolutions commented 3 years ago

You could emulate RIGHT JOIN with LEFT JOIN by swapping the position table when selecting it.

Select * from categories_subcategoris left join categories on categories.id = categories_subcategories.categories_id left join sub_categories on categories_subcategories.subcategories_id = subcategories.id

Hope it help.

Thanks! it worked!