Click to See Complete Forum and Search --> : Recursive Select


mima
11-01-2007, 05:23 AM
Hi,

I’m having following table structure

Table Locations
ID ParentID
1 0
2 1
3 2
4 3
5 4

Table Properties
LocationID Location
1 Europe
2 Western Europe
3 Germany
4 Bavaria
5 Berlin

Represented data in this case means that I have location Europe with its child location Western Europe with child location Germany with child location Bavaria with child location Berlin.
Europe > Western Europe > Germany > Bavaria > Berlin

Now I need SQL statement to perform search on following way:
For example if I search for Western Europe it needs to return not just Western Europe but its child’s to, in this case Germany, Bavaria and Berlin.

Any help appreciated,
Thanks in advance

chazzy
11-04-2007, 01:41 PM
unfortunately mysql doesn't support a hierarchical query (which is what you're asking for). You'll need to write a stored procedure.

The alternative would be create some kind of table that handles threading. "Western Europe" would be considered the parent of all of those items in this threaded table.