Select A,A from .... 2 fields with different values,

sigeargentina
04 de Agosto del 2004
I have two tables in Sql Server. The first one called "Details"
(1)IdUser
(2)IdUser2
(3)ProcessDescription

The second Table Users:
(1)IdUser
(2)Name

I need to see both User1 and User2 for each register in Details but don´t know how to do that.
Select Users.Name,Users.Name from Users inner join ...... ?????

semperfimxl
04 de Agosto del 2004
SELECT Users.IdUser, Details.IdUser2, Users.Name, Details.ProcessDescription From Users LEFT JOIN Details ON Details.IdUser = Users.IdUser ORDER BY Users.IdUser;

semperfimxl
04 de Agosto del 2004
The above will show up all the records from the Users table and only those of Details whose IdUser field match the IdUser field in the Users Table...

If, on the other hand, you want to see all the records from the Details table along with their correspondent Name from the Users table, then use the next:

SELECT Details.IdUser, Details.IdUser2, Users.Name, Details.ProcessDescription From Details LEFT JOIN Users ON Details.IdUser = Users.IdUser ORDER BY Details.IdUser;

Hope this is what you need ...

Cheers !


www.vcardona.com
04 de Agosto del 2004
This is one metod,

select users.name from user,details
where users.iduser = details.iduser
union all
select users.name from user,details
where users.iduser = details.iduser2