The task in my opinion is non-trivial. There are three tables:
user(it stores information about the builders);sfera(it stores information about the categories in which builders provide their services);favorites(it stores information about builders that users have added to their favorites, broken down into categories; that is, the same builder can provide services in three categories, but at the same time be added to favorites in only one category).
When we load a catalog of builders in a specific category, for example, “Interior Works”, we select them as follows:
SELECT sfera.*, user.photo as photo, user.city as city, sfera.additional FROM sfera, user WHERE sfera.is_confirmed = '1' AND sfera.sfera_value = 'Внутренние работы' AND sfera.city_value = 'Москва' AND user.user_id = sfera.user_id ORDER BY rating DESC Question :
How to add to the results of the request information about whether the builder has a mark of adding to favorites in this category (Internal work)?
The table structure favorites :
id // id записи person_id // id пользователя, добавившего строителя в избранные user_id // id строителя, добавленного в избранные sferaValue // идентификатор конкретной категории, в которой строитель добавлен в избранные is_favorite // по умолчанию 1
,in with a full join and add the left join subquery that receives id from the third id-table, group categories with group by for these fields, i.e. so that he would have no more than one entry per category user - Mike,no different, only the join condition from where is transferred toonthis join - Mike