Help me.subquery belonging to a person on a single line on the lines of the Display.

CREATE TABLE STUDENTS
(
NUMBER OF OPPORTUNITY,
NAME VARCHAR2 (30 BYTE),
STUDENT_ID);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
1, "Carol Haan", 1);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
3, "Saskia Tune", 2);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
1, "Saskia Tune", 2);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
2, "Saskia Tune", 2);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
3, "Mark Quin', 1);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
4, 'Aretha June', 3);
INSERT INTO STUDENT (LANGUAGE_ID, STUDENT_ID, NAME) VALUES)
1, 'Aretha June', 3);
COMMIT;



CREATE TABLE STUDENTS_JOBS
(
JOB_ID NUMBER,
JOBNAME VARCHAR2 (20 BYTE),
LANGUAGE_I);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
1, "Registrar", 1);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
2, 'reception clerck', 2);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
2, 'reception clerck', 1);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
2, 'reception clerck', 3);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
3, 'manager', 1);
INSERT INTO STUDENTS_JOBS (JOB_ID, JOBNAME, LANGUAGE_ID) VALUES)
3, 'manager', 4);
COMMIT;


CREATE TABLE STUDENT_LANGUAGES
(
NUMBER OF OPPORTUNITY,
LANGUAGE VARCHAR2 (30 BYTE)
);
INSERT INTO STUDENT_LANGUAGES (LANGUAGE_ID, LANGUAGE) VALUES)
1, 'English');
INSERT INTO STUDENT_LANGUAGES (LANGUAGE_ID, LANGUAGE) VALUES)
2, "Dutch");
INSERT INTO STUDENT_LANGUAGES (LANGUAGE_ID, LANGUAGE) VALUES)
3, 'Spanish');
INSERT INTO STUDENT_LANGUAGES (LANGUAGE_ID, LANGUAGE) VALUES)
4, "Japanese");
INSERT INTO STUDENT_LANGUAGES (LANGUAGE_ID, LANGUAGE) VALUES)
5, 'German');
COMMIT;
I, ve worked with languages_id. the aiming languages_id students and students_jobs at the same
opportunity in the student_languages. In the subquerie following students who speak the
the languages that are required in the student_jobs are derived.
In the example, the used job_id argument is 1, it's just in the example but it could be any job_id.

SELECT DISTINCT
$m.name
m.student_id
s.language
students m, student_languages s
Where s.language_id = m.language_id
and not EXISTS
((select opportunity
of students_jobs
where job_id = 1) less (select opportunity
students
where student_id = m.student_id));

The result is as follows:
STUDENT_ID LANGUAGE NAME
English Aretha June 3
Japanese Aretha June 3
Carol Haan 1 English
Saskia Tune 2 Dutch
Saskia Tune 2 English
Saskia Tune 2 Spanish


The problem is that I need a query that can put the languages in addition to the person (a line), with the language of a person in a line and not separately in different lines.
the result should be as follows:
student_id language name
3 June Aretha English, Japanese
Carol Haan 1 English
Saskia Tune 2 Dutch, English, Spanish

I don't know if this can be done with prior agreement. I really need help.
Can someone help me pleasse. Don't mind English mine.

Greetings,
Caroline

Hi, Caroline.

What you want is called "Aggregation of String": make a long list, delimited containing any number of individual elements (language names, in this case).
This page:
http://asktom.Oracle.com/pls/asktom/f?p=100:11:0:P11_QUESTION_ID:2196162600402
has several techniques.
I use (and recommend) one, a user-defined function called STRAGG which can be copied directly from the above site.
When you have installed STRAGG, you can get the results you want like this:

SELECT    m.name
,         m.student_id
,         STRAGG (s.language)   AS all_languages
from      students m
,         student_languages s
Where     s.language_id = m.language_id
and       not EXISTS
          (       ( select  language_id
                    from    students_jobs
                    where   job_id = 1
                  )
          minus   ( select language_id
                    from   students
                    where   student_id = m.student_id
                  )
          )
GROUP BY  m.name
,         m.student_id;

In Oracle 10 (and more) you can have a function like STAGG, called WM_CONCAT, that is already available.

The site referenced above also shows how string aggregation using the "CONNECT BY...» BEFORE... ", as you said.

Thank you for including CREATE TABLE and INSERT!

Tags: Database

Similar Questions

Maybe you are looking for