I have read a similar questions but it didn't work!
我已经阅读了类似的问题,但它没有用!
I Have a table like this:
我有这样一张桌子:
ID IDParent Name
---------------------------
01 Parent
02 01 Child01
02 01 Child02
I Have to write a Query that returns the following table:
我必须编写一个返回下表的Query:
ID Name1 Name
---------------------------
01 Parent
02 Parent Child01
02 Parent Child02
I tried this query but it did not work:
我尝试了这个查询,但它不起作用:
SELECT * FROM SomeTable
JOIN SomeTable ON SomeTable.ID = SomeTable.IDParent;
2 个解决方案
#1
2
You have to use table alias here:
你必须在这里使用表别名:
SELECT t.Id, p.Name AS Name1, t.Name
FROM Table t
JOIN Table p ON p.ID = t.IDParent;
#2
0
Try by creating the alias of your class known as self join
like this:-
尝试创建类的别名,称为自连接,如下所示: -
SELECT t.Id, p.Name as name, t.Name
FROM Table t
JOIN Table p ON p.ID = t.IDParent;
#1
2
You have to use table alias here:
你必须在这里使用表别名:
SELECT t.Id, p.Name AS Name1, t.Name
FROM Table t
JOIN Table p ON p.ID = t.IDParent;
#2
0
Try by creating the alias of your class known as self join
like this:-
尝试创建类的别名,称为自连接,如下所示: -
SELECT t.Id, p.Name as name, t.Name
FROM Table t
JOIN Table p ON p.ID = t.IDParent;