query category wise dara I have stored the some products and there respective category in sql.

Like this. Now I want fetch all product from table with respective category.
output should be=&gt;
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