Im trying to match both userIngredient.i_id and recipe_ingredient.i_id and match and compare all values of recipe_ingredient.i_id, the query I tried only displays all matching i_id's without the non matching i_id's, heres the data-
recipe_ingredients table:
+---------+------+
| post_id | i_id |
+---------+------+
| ifqnnv | 1 |
+---------+------+
| ifqnnv | 2 |
+---------+------+
| ifqnnv | 3 |
+---------+------+
| ifqnnv | 4 |
+---------+------+
userIngredient table:
+---------+------+
| user_id | i_id |
+---------+------+
| 4 | 1 |
+---------+------+
| 4 | 2 |
+---------+------+
| 4 | 3 |
+---------+------+
Query that I've tried:
SELECT userIngredients.i_id,recipe_ingredients.i_id, recipe_ingredients.recipe_id,
CASE
WHEN userIngredients.i_id = recipe_ingredients.i_id THEN "true"
WHEN userIngredients.i_id != recipe_ingredients.i_id THEN "false"
END as state
FROM userIngredients
LEFT OUTER JOIN recipe_ingredients
ON userIngredients.i_id = recipe_ingredients.i_id
WHERE userIngredients.uid = 4 AND recipe_ingredients.post_id = 'ifqnnv'
Output I got:
+------+------+-----------+-------+
| i_id | i_id | recipe_id | state |
+------+------+-----------+-------+
| 1 | 1 | ifqnnv | true |
+------+------+-----------+-------+
| 2 | 2 | ifqnnv | true |
+------+------+-----------+-------+
| 3 | 3 | ifqnnv | true |
+------+------+-----------+-------+
Desired output:
+------+------+-----------+-------+
| i_id | i_id | recipe_id | state |
+------+------+-----------+-------+
| 1 | 1 | ifqnnv | true |
+------+------+-----------+-------+
| 2 | 2 | ifqnnv | true |
+------+------+-----------+-------+
| 3 | 3 | ifqnnv | true |
+------+------+-----------+-------+
| null | 4 | ifqnnv | false |
+------+------+-----------+-------+