I have this table that is referencing itself.
我有这个表正在引用它自己。
Is there a way to show the parent name in a query? Something like if (parent_id != null) {SHOW name WHERE id=parent_id} else {is_parent = TRUE)
. This is just how I see the logic.
是否有方法在查询中显示父名称?类似if (parent_id != null){显示id=parent_id} else {is_parent = TRUE的名称。这就是我的逻辑。
1 个解决方案
#1
3
Maybe simply:
也许简单:
SELECT U.*, UP.name
FROM units U
LEFT JOIN units UP ON U.parent_id = UP.id
?
吗?
#1
3
Maybe simply:
也许简单:
SELECT U.*, UP.name
FROM units U
LEFT JOIN units UP ON U.parent_id = UP.id
?
吗?