Skip to content

Instantly share code, notes, and snippets.

@cnstlungu
Last active November 5, 2022 21:24
Show Gist options
  • Save cnstlungu/95fea3e49a750d863039e9d6e52f0d2d to your computer and use it in GitHub Desktop.
Save cnstlungu/95fea3e49a750d863039e9d6e52f0d2d to your computer and use it in GitHub Desktop.
Avoid nested queries
-- 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