Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8903847
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:58:22+00:00 2026-06-15T01:58:22+00:00

I managed to solve it using UNION between two querys, I belive my attempt

  • 0

I managed to solve it using UNION between two querys, I belive my attempt was a little off and tried to do a mathematical add. This is problaby not the best way you can do it, but it worked and that’s enough for me. Thank you for your help.

Working solution:

CREATE VIEW Registrations AS
(SELECT S.identificationnumber AS StudentId, S.name AS StudentName, C.code AS CourseCode, C.name AS CourseName, 'Waiting' AS Status
FROM  Waitinglist W, Student S, Course C
WHERE S.identificationnumber = W.identificationnumber
AND W.code = C.code) UNION (SELECT S.identificationnumber AS StudentId, S.name AS StudentName, C.code AS CourseCode, C.name AS CourseName, 'Registered' AS Status
FROM  Registeredat R, Student S, Course C
WHERE S.identificationnumber = R.identificationnumber
AND R.code = C.code);

Origianl Problem:

I’m a begginner at databases and SQL, so things might not look that professional.

What I’m trying to do in plain text:
I’m trying to create a view for all registerd and waiting students, for all courses. I also want to add a new “column” thats either “registerd” or “waiting”.

How I want the view to look:

StudentID, StudentName, CourseCode, CourseName, Status

StudentID = Combined idenficationnumber for Table "RegisterdAt" and "Waitinglist"
StudentName = Based on StudentID find matching name in Table "Student"
CourseCode = Combined code for Table "RegisterdAt" and "Waitinglist"
CourseName = based on code find matching name in Table "Course"
Status = Either "registered" or "waiting" 
   depending on if we got the "row" from Table "RegisterdAt" or "Waitinglist" 

The Created Tables(I have also added some examplery data into them, for easier testing):

CREATE TABLE Student(
identificationnumber  VARCHAR(20),
name VARCHAR(50),
branchname VARCHAR(50),
programmename VARCHAR(50),
PRIMARY KEY(identificationnumber),
FOREIGN KEY(branchname, programmename) REFERENCES Branch(name, programmename)
);

CREATE TABLE Course(
code CHAR(6),
name VARCHAR(50),
credits VARCHAR(10),
departmentname VARCHAR(50),
PRIMARY KEY(code),
FOREIGN KEY(departmentname) REFERENCES Department(name)
);

CREATE TABLE Waitinglist(
identificationnumber VARCHAR(20),
code CHAR(6),
ddate VARCHAR(10),
PRIMARY KEY(identificationnumber, code),
FOREIGN KEY(identificationnumber) REFERENCES Student(identificationnumber),
FOREIGN KEY(code) REFERENCES Course_with_maxstudents(code)
);

CREATE TABLE Registeredat(
identificationnumber VARCHAR(20),
code CHAR(6),
PRIMARY KEY(identificationnumber,code),
FOREIGN KEY(identificationnumber) REFERENCES Student(identificationnumber),
FOREIGN KEY(code) REFERENCES Course(code)
);

An attempt to create a view(not working, and missing registerd/waiting attribute):

CREATE VIEW Registrations AS
SELECT (R.identificationnumber + W.identificationnumber) AS StudentId, S.name AS StudentName, (R.code + W.code) AS CourseCode, C.name as CourseName
FROM  Registeredat R, Waitinglist W, Student S, Course C
WHERE S.identificationnumber = (R.identificationnumber + W.identificationnumber)
AND C.code = (R.code + W.code);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:58:23+00:00Added an answer on June 15, 2026 at 1:58 am

    The working solution you posted looks great. I would just make the plain UNION into a UNION ALL, for it seems unlikely for you to need to remove duplicates from between these 2 subqueries. The ALL will prevent the server from doing unnecessary work to resort the combined results and search for non-existant duplicates.

    So it would become:

    CREATE VIEW Registrations AS  
    (
        SELECT S.identificationnumber AS StudentId, S.name AS StudentName, C.code AS CourseCode, C.name AS CourseName, 'Waiting' AS Status  
        FROM  Waitinglist W, Student S, Course C  
        WHERE S.identificationnumber = W.identificationnumber  
        AND W.code = C.code  
    )  
    UNION ALL  
    (  
        SELECT S.identificationnumber AS StudentId, S.name AS StudentName, C.code AS CourseCode, C.name AS CourseName, 'Registered' AS Status  
        FROM  Registeredat R, Student S, Course C  
        WHERE S.identificationnumber = R.identificationnumber  
        AND R.code = C.code  
    );  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

EDIT: Please ignore this question - I've managed to solve it in a way
I've managed to manually detect rotation and set my own rotation effects between two
EDIT: I have managed to solve the problem by using: +lorem ipsum +type:photo +lorem
I am trying to add filters to this query using ICriteria. Through the rest
I'm using boost::interprocess to communicates between two applications. When the two applications are launch
I can't find a solution for that. I managed to solve the problem of
I managed to create a dynamic three dropdown list using Javascript code and it
I managed to apply this excellent example to my needs: http://code.google.com/p/galleriffic/issues/attachmentText?id=76&aid=-3045121742886940548&name=example-2.html&token=4nlvmgAfVpc5whcXC9UEqHZaSz0%3A1339257750721 With a small
Solved: i just managed to solve the problem by creating a new table and
This is more of an intriguing problem than anything else since I have managed

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.