0
$\begingroup$

I have stored the some products and there respective category in sql. enter image description here

Like this. Now I want fetch all product from table with respective category. output should be=> enter image description here

$\endgroup$
2
  • $\begingroup$ Please edit the question to explain, precisely, how the output is obtained from the input. $\endgroup$ Commented Dec 14, 2020 at 11:59
  • $\begingroup$ name is the set of all distinct products and categories, and flag_for_ca is a bit field (Y/N) if the name is a category?? $\endgroup$ Commented Feb 19, 2021 at 15:50

1 Answer 1

1
$\begingroup$

assuming your products table is called products the following sql statement would achieve this


SELECT DISTINCT id, category as name, 1 as flag_for_ca FROM products
UNION ALL
SELECT DISTINCT id, prodct as name, 0 as flag_for_ca FROM products

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.