bun butter
bun butter

Reputation: 29

Display Student's firstname and course enrolled by him in Oracle

people the question is to write a query to display the student's first name alone with the course name that they have registered. Sort the result based on student's first name and course name.

Here is my attempt to solve the problem,

select FirstName,CourseName from student s
inner join registration r on s.StudID=r.StudId
inner join course c on r.CourseID=c.CourseID
order by FirstName asc,CourseName asc;

This is the schema for the tables enter image description here

The output i get when i run the code is this output

Where am i going wrong? please help people.

Upvotes: 1

Views: 5139

Answers (2)

rampentapati1111
rampentapati1111

Reputation: 11

I did this and got the required output.

select FirstName,CourseName from ((student s
inner join registration r on s.StudID=r.StudId)
inner join course c on r.CourseID=c.CourseID)
order by FirstName asc,CourseName asc;

Upvotes: 0

MT0
MT0

Reputation: 167867

From your comment:

the output seems to be printing two tables as you can see in the picture i think they should be printed in the same table

No, it isn't. You appear to be using SQL/Plus and its all part of the same output; its just that after a certain number of rows SQL/Plus will re-print the column headers.

The commands for SQL/Plus are given here and you should be able to use:

SET PAGESIZE 10000

(Or some other large value) and that will set the number of rows that SQL/Plus will output before it repeats the headers. Then you can re-run your query and the repeated headers will not be printed.

Upvotes: 2

Related Questions