How can I create a view in mysql?
Attaching the screenshot as required.
How can I create a view in mysql?
Attaching the screenshot as required.
You can solve it with conditional aggregation (If I understood correctly table1 contains the ID, and table2 contain the products?
Use this:
CREATE VIEW YourViewName AS
SELECT t.id,
MAX(CASE WHEN t.product = 'apple' then 'Y' END) as apple,
MAX(CASE WHEN t.product = 'guava' then 'Y' END) as guava,
MAX(CASE WHEN t.product = 'mango' then 'Y' END) as mango,
MAX(CASE WHEN t.product = 'cherry' then 'Y' END) as cherry,
MAX(CASE WHEN t.product = 'carrot' then 'Y' END) as carrot
FROM(SELECT t1.id,t3.product FROM Table1 t1
LEFT JOIN Table3 t3
ON(t1.id = t3.id)) t
GROUP BY t.id