うーん - 基本的な質問はすでに回答されているようです。しかし、あなたのセットアップは私を少し悩ませています...
私はあなたのテーブルを少し再構築すると思います(国際化が問題ではないと仮定します)。とりわけ、「カテゴリー」と「ギャラリー」の概念に根本的な違いはないと思います。現在、「スーパー」および「サブ」カテゴリ/ギャラリーが存在する場合があり、画像が一度に複数に属する場合があります (つまり、レニアサンス、ミケランジェロ、彫刻など)。タグの概念に似ています。
私はおそらくあなたのテーブルを次のように修正します:
Gallery (or Category, if you prefer)
=============
id -- autoincrement
name -- varchar(50) or something, unique
parent -- fk reference to another Gallery.id row, optional
Image
==========
id -- autoincrement
name -- varchar(50) or similar, non-unique
path -- store as URI/URL, unique
description -- varchar(128) or similar
Gallery_Image
===============
galleryId -- fk reference to Gallery.id
imageId -- fk reference to Image.id
-- the pair is unique
Related_Gallery -- optional table
================
galleryId -- fk reference to Gallery.id
relationship -- code, or fk reference to other table
relatedId -- fk reference to Gallery.id
-- entire row should be unique
-- somewhat tricky to use.