Click here to Skip to main content
15,892,059 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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 .
Posted

Your question is not clear. As I understand you want to select from both tables based on id or
did I miss anything.

SQL
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[^]
 
Share this answer
 
Comments
mojtaba pirveisi 16-Feb-11 3:56am    
In fact, my [groupUser] table store 2 user id , userID1,userID2 that i want to show their name instead of their id in select statement
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]


I think you should reconsider the design of the table [groupUser], what if later you need 3 or more users in a group?
 
Share this answer
 
Comments
mojtaba pirveisi 16-Feb-11 8:30am    
I think it should like this , thanks . but what do you suggest about designing this table for more that 2 user in a group

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900