Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
danny77uk
Starting Member
2 Posts |
Posted - 2007-08-06 : 07:12:57
|
| Hi I'm new to SQL and I'm having some problems with the following join. I have a table, Ticket, with two int fields, Submitter and Acceptor, among many others. These fields reference the ID of users stored in the Users table and are usually set to different IDs (ie. they are independant fields).Here is the relevent SQL to get the ticket records (generated by the Query Editor in SQL Management Studio Express):SELECT Users.Name, Tickets.IDFROM Tickets INNER JOIN Users ON Tickets.Submitter = Users.ID AND Tickets.Acceptor = Users.ID Problem is, this only returns records where the submitter and acceptor IDs are the same which is rarely the case. What am I doing wrong here? I've created a lot of joins for other records without problem - this is the only case where two fields are coming from the same table.Thanks for any help. |
|
|
pootle_flump
1064 Posts |
Posted - 2007-08-06 : 07:20:34
|
| [code]SELECT subs.Name AS sub_name, accs.Name AS acc_name, Tickets.IDFROM Tickets INNER JOIN Users AS subs ON Tickets.Submitter = subs.ID INNER JOIN Users AS accs ON Tickets.Acceptor = accs.ID[/code] |
 |
|
|
danny77uk
Starting Member
2 Posts |
Posted - 2007-08-06 : 07:36:11
|
| Wow fast response! That works great thanks! |
 |
|
|
|
|
|