现在我有了这个表redirect
是id
id name redirect
1 a null
2 b null
3 c null
4 d 1
5 e 3
我在开头只有name
,我需要此查询=> If redirect is not null then get the new name from where redirect is pointing at.
:如果我在开头有a
,则不执行任何操作,因为重定向为空。但如果我在开始时d
转到id = 1
并获取a
答案 0 :(得分:0)
使用自我加入:
SELECT t1.name
FROM yourTable AS t1
JOIN yourTable AS t2 ON t1.id = t2.redirect
WHERE t2.name = 'd'