[b]data in myTable[/b]
[COLOR="Blue"](id) mom geo[/COLOR]
(0) 0 earth
(1) 0 North America
[COLOR="Red"](2)[/COLOR] 1 America
(3) 0 Europe
(4) 2 L.A.
(5) 2 New York
(6) 5 Manhatan
(7) 3 France
(8) 7 Paris
I have data in myTable like the above.
When variables.V is COLOR=“Red”[/COLOR], The SQL below produces the result below.
[b]sql[/b]
select DISTINCT t1.id, t1.mom, t1.geo
from myTable t1
join myTable t2
on t1.id = t2.mom
join myTable t3
on t2.id = t3.mom
where t1.id = #variables.V# or
t2.id = #variables.V# or
t3.id = #variables.V#
order by id
</cfquery>
[b]result[/b]
(0) 0 earth
(1) 0 North America
(2) 1 America
So far, so good.
But let’s suppose (ID) order is not ordered like the below.
[b]data in myTable1[/b]
[COLOR="Blue"](id) mom geo[/COLOR]
(0) 0 earth
([B]2[/B]) 0 North America
[COLOR="Red"](1)[/COLOR] [B]2[/B] America
(3) 0 Europe
(4) [B]1[/B] L.A.
(5) [B]1[/B] New York
(6) 5 Manhatan
(7) 3 France
(8) 7 Paris
When variables.V is 1 with the data in myTable1,
The code below produces the result below.
[b]sql[/b]
select DISTINCT t1.id, t1.mom, t1.geo
from myTable1 t1
join myTable1 t2
on t1.id = t2.mom
join myTable1 t3
on t2.id = t3.mom
where t1.id = #variables.V# or
t2.id = #variables.V# or
t3.id = #variables.V#
order by [COLOR="Red"][B]id[/B][/COLOR]
</cfquery>
[b]result[/b]
(0) 0 earth
(2) 1 America
(1) 0 [COLOR="red"]North America[/COLOR]
How can I get my target result below with the data in myTable1?
[b]target result[/b]
(0) 0 earth
(1) 0 [COLOR="Red"]North America[/COLOR]
(2) 1 America
“order by t” was one of my trials, but it’s failed.
If I remove ORDER CLAUSE, the order seems arbitrary.