• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Please..... Help....

#1
[eluser]Bluemagix[/eluser]
Hello,
I have table called category
having fields, records like this

id name parentid
1 Bank 0
2 Shopping 0
3 Axis 1
4 ICICI 1
5 SBI 1
6 Nike 2
7 xyz 2

where parentid 0 means major categories.
and for other is shows the sub category according to parentid

Eg: icici's parentid is 1 because it comes under bank [having id]

Now, i want result as
Bank
Axis
ICICI
SBI
Shopping
Nike
xyz


How can i do that??
which query i should use??

#2
[eluser]davidbehler[/eluser]
try something like this:
Code:
select *, CASE parentid when "0" then id else parentid
END as order_by
from category
order by order_by ASC, parentid ASC

that's untested and might need some tweaking, but in my opinion something like this should work for you.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.