I have a simple relation in which category and subcategories are differentiated by parent_id and category has a parent_id 0 and subcategory has category_id as its parent_id.What i want to do is to select first subcategory of a first category.
for this i am using
SELECT cat_id FROM member_product_cat WHERE cat_parent_id !=0 HAVING
cat_parent_id=min(cat_parent_id) LIMIT 1
but it gives me an error.I know i can do the same by
SELECT cat_id FROM member_product_cat WHERE cat_parent_id=(Select
min(cat_parent_id) from member_product_cat where cat_parent_id !=0)
LIMIT 1
But what is wrong in my first approach?isnt it for this we have having clause?.
Regards
Himanshu Sharma
The HAVING clause was added to SQL because the WHERE keyword could not be used with aggregate functions. So you do not need HAVING there at all.