选择列insql服务器上的问题
问题描述:
HI
我正在开发数据库应用程序.
我有一个表名存储ID,名称,信息,地址,...的人.还有另一个存储2个ID的表名组,这两个ID都指向表People的ID.
我想从组表中选择,但要选择ID而不是ID,我该怎么做.对不起,我的英语不好.
HI
I am working on a database application.
I have a Table name people that store ID , name , info , address ,... ; And another table name group that store 2 id that both of them point to id of table People .
I want to select from group table but instead of id , their name would be selected , How can I do that . sorry for my bad english .
答
您的问题不清楚.据我了解,您想基于id或
从两个表中进行选择 我错过了什么吗?
Your question is not clear. As I understand you want to select from both tables based on id or
did I miss anything.
Select c.id, c.Name, c.Address, ct.groupname, ct.ID FROM people AS c Inner Join [group] as ct on ct.ID=c.id
sql joins[^]
这是您想要的吗?
Is this what you want?
SELECT u.[name]
FROM [users] u
JOIN [groupUser] gr1
OM gr1.[userID1] = u.[userId]
JOIN [groupUser] gr2
OM gr1.[userID2] = u.[userId]
我认为您应该重新考虑表[groupUser]的设计,如果以后在一个组中需要3个或更多用户怎么办?
I think you should reconsider the design of the table [groupUser], what if later you need 3 or more users in a group?