Last active
November 5, 2022 21:24
-
-
Save cnstlungu/95fea3e49a750d863039e9d6e52f0d2d to your computer and use it in GitHub Desktop.
Avoid nested queries
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- avoid | |
SELECT | |
products.product_name AS name, | |
prices.product_price AS price | |
FROM | |
( | |
SELECT | |
1 AS product_id, | |
5 AS product_price | |
UNION ALL | |
SELECT | |
2 AS product_id, | |
4 AS product_price | |
) prices | |
JOIN | |
( | |
SELECT | |
1 AS product_id, | |
'notebook' AS product_name | |
UNION ALL | |
SELECT | |
2 AS product_id, | |
'pen' AS product_name | |
) products ON products.product_id = prices.product_id | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment