Simple and easy explanation for beginners
\nSELECT product_id, \'store1\' AS store, store1 as price FROM products WHERE store1 IS NOT NULL\nUNION \nSELECT product_id, \'store2\' AS store, store2 as pric
```\nSELECT product_id, \'store1\' AS store, store1 as price FROM products WHERE store1 IS NOT NULL\nUNION \nSELECT product_id, \'store2\' AS store, store2 as price FROM products WHERE store2 IS NOT NULL\nUNION \nSELECT product_id, \'store3\' AS store, store3 as price From products WHERE store3 IS NOT NULL\nORDER BY 1,2 ASC;\n```\nlet us understand it in parts\n```\nSELECT product_id, \'store1\' AS store, store1 as price FROM products WHERE store1 IS NOT NULL\n```\nselect \'store1\' as store => does nothing but add a column named store in which you can add any value(here \'store1\') manually, \nnow we select store1 as price where store1 is not null => this statement gives you the values present only in column store1 naming it price.\nNow after this we use union for adding the entries for other stores as well in the same pattern and after that order it by product_id.\n\nI would recommend running only first line and see the output and then run the whole code without the last line for a better understanding.\n\nIf you have any doubt feel free to ask in the comments.\n\nPlease upvote if you found this useful.\n
['Union Find', 'MySQL']