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
 General SQL Server Forums
 New to SQL Server Programming
 how to get Distinct id with same value

Author  Topic 

Madhavi.extarc
Starting Member

7 Posts

Posted - 2014-04-18 : 05:17:04
Hi All,

I have data like this

course_id Session
--------- --------
1234 8.00 - 10.00
4567 8.00 - 10.00

From the above table i want the result to be like this

course_id1 course_id2 session
---------- ---------- -------
1234 4567 8.00 - 10.00

Get someone get me a query to get the above result format

Madhavi

nagino
Yak Posting Veteran

75 Posts

Posted - 2014-04-18 : 05:45:02
SELECT
T1.course_id course_id1,
T2.course_id course_id2,
T1.session
FROM YourTable T1
INNER JOIN YourTable T2
ON T1.course_id < T2.course_id
AND T1.Session = T2.Session


-------------------------------------
From Japan
Sorry, my English ability is limited.
Go to Top of Page

Madhavi.extarc
Starting Member

7 Posts

Posted - 2014-04-18 : 06:01:46
thank u nagino.



Madhavi
Go to Top of Page

MuralikrishnaVeera
Posting Yak Master

129 Posts

Posted - 2014-04-18 : 06:15:21
Another way....


DECLARE @TEMP TABLE(course_id INT ,Session VARCHAR(MAX))
INSERT INTO @TEMP VALUES(1234, '8.00 - 10.00'),(4567, '8.00 - 10.00')

SELECT [1234] AS CourseID_1,[4567] AS CourseID_2,[SESSION] FROM @TEMP
PIVOT( MAX(course_id) FOR course_id IN ([1234],[4567]))Pvt


---------------
Murali Krishna

You live only once ..If you do it right once is enough.......
Go to Top of Page
   

- Advertisement -