Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
SQL
SELECT COURSEID, COURSENAME, COURSEGROUP
FROM SOME_VIEW
WHERE STUDENTID=:STU_ID
--GROUP BY COURSEID, COURSENAME
ORDER BY COURSEID


I want the previous code to work like the following
if we have 2 data Rows


COURSEID-------COURSENAME------COURSEGROUP

PHY144----------physics------------------A

PHY144----------physics------------------B


What I really need is

COURSEID-------COURSENAME------COURSEGROUP

PHY144----------physics------------------A, B


please help me
Posted
Updated 19-Mar-12 22:53pm
v2

You will have to write a sub query. You can not have a comma separated aggregate using group by alone. You can find an example here http://stackoverflow.com/questions/7448734/sql-comma-separated-row-with-group-by-clause[^]
 
Share this answer
 
Comments
kareem salem 20-Mar-12 8:12am    
thanks for your time
your link helped my somehow but the magic function wm_concat solved it

SELECT COURSEID, COURSENAME, WM_CONCAT(COURSEGROUP)
WHERE STUDENTID=:STU_ID
GROUP BY COURSEID, COURSENAME
Saral S Stalin 20-Mar-12 9:23am    
Hmm...There is no equvalent of WM_CONCAT in SQL Server. So we are stuck with a subquery in the select
kareem salem 21-Mar-12 4:58am    
I think there's something I get during my search like "FOR XML PATH" in SQL server. and Isn't supported by Oracle. I don't know more info about it
hi,
try this,

SQL
SELECT COURSEID, COURSENAME, COURSEGROUP
FROM SOME_VIEW
GROUP BY COURSEID, COURSENAME
HAVING STUDENTID=STU_ID
 
Share this answer
 
v2
Comments
kareem salem 20-Mar-12 5:13am    
hi Hrushikeshphapale,
thank you for your fast replyin
I tried this and It doesn't work
I get this error
ORA-00979: not a GROUP BY expression

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900