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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 To return distinct column using INNER JOIN

Author  Topic 

Mooo0
Starting Member

4 Posts

Posted - 2008-04-23 : 21:57:40
Hello all,

I am using INNER JOIN to connect 2 tables together but I wish it to return distinct columns instead of repeating itself !

eg.
Current output would be:
UserID Name UserID OrderID
1 John 1 5
2 Bob 2 6

I want it to be:
UserID Name OrderID
1 John 5
2 Bob 6


I need to use SELECT * as there are many many columns and wish to save time :)


Cheers,

James

sodeep
Master Smack Fu Yak Hacker

7174 Posts

Posted - 2008-04-23 : 22:03:14
So what you mean? Do you have table with duplicate column name?
Go to Top of Page

Mooo0
Starting Member

4 Posts

Posted - 2008-04-23 : 22:09:55
Ahh yes, should have mentioned the tables that I am using:

Tables I'm using might look like this

TableA
UserID Name


TableB
UserID OrderID

and I am getting duplicate columns when I use INNER JOIN together
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-04-23 : 23:50:36
There is no other way but to specify only the columns that you require in select list. Using select * selects all the columns from tables involved and you will get same column repeated from different tables.
Go to Top of Page
   

- Advertisement -