I need help writing a SQL VIEW query for the following scenario:Here is the query which I have tried but it only return the matched data, because any someone user_id is matched to any of the recipe:
CREATE VIEW view_recipebank ASSELECTr.*,IFNULL(f.status, "0") as favourite,f.user_id as f_user_id,f.status as f_status,FROM tbl_recipes as rLEFT JOIN tbl_favourites as f ON f.type = "recipe" AND f.type_id = r.recipe_idWHEREr.status = '1' AND r.is_hide_recipebank = '0'I have two tables, tbl_recipes and tbl_favourites. The tbl_recipes table stores all the recipes and is used to display recipes to users with pagination. The tbl_favourites table stores the recipe_id and user_id to track which recipes each user has marked as their favorites.
I need a VIEW query that returns all recipes along with an additional column that indicates whether each recipe is a favorite for a specific user. If a recipe is a favorite, the column should return 1; otherwise, it should return 0.
How can I write a VIEW query to achieve this? Thank you!