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 2000 Forums
 Transact-SQL (2000)
 make SELECT

Author  Topic 

Maharisi
Starting Member

19 Posts

Posted - 2008-01-11 : 03:50:36
How can I join row from first table and row from second table to only one row with only one SELECT statement.

Thanks so much
maharisi

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-11 : 04:24:21
on what condition? plzz give structure of tables and expected output.
Go to Top of Page

Maharisi
Starting Member

19 Posts

Posted - 2008-01-11 : 04:32:43
OK I have only one TABLE for example:
ID Name
1 John
2 Tom

I need join these two rows to only one row looks like
Name1 Name2
John Tom

but only one SELECT statement and I need use two different WHERE conditions ID
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-01-11 : 04:50:18
quote:
Originally posted by Maharisi

OK I have only one TABLE for example:
ID Name
1 John
2 Tom

I need join these two rows to only one row looks like
Name1 Name2
John Tom

but only one SELECT statement and I need use two different WHERE conditions ID


If you have only two rows then

select
max(case when id=1 then name end) as Name1 ,
max(case when id=2 then name end) as Name2
from yourTable


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Maharisi
Starting Member

19 Posts

Posted - 2008-01-11 : 05:02:34
I dont have only two rows.

Thanks Madhivanan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-01-11 : 05:14:17
Try this:-
SELECT t1.Name AS 'Name1',t2.Name AS 'Name2'
FROM Table t1
CROSS JOIN Table t2
WHERE t1.ID = @ID1
AND t2.ID=@ID2

@ID1 & @ID2 are your reqd IDs to be passed to query
Go to Top of Page

Maharisi
Starting Member

19 Posts

Posted - 2008-01-11 : 07:49:38
thanks a lot
Go to Top of Page
   

- Advertisement -