title: Removing Duplicates added by foriegn key in Oracle DB
body: <p>I'am working on a Hostel Project in Oracle DB, I have 2 tables (students,rooms) and when I run query to get name of students ,their room IDs and facilities that are provided to them it returns duplicate student names with all the facilities and with little editing in query it returns duplicate facilities.  </p>
  
  <p>How can I fix those duplicates?
  Here is the Code</p>
  
  <pre><code>    --CREATE TABLE STUDENTS
      Create table students(
      regno integer primary key,
      name varchar2(30),
      phonenum number,
      address varchar2(30),
      roomalloc number 
      );
  
      Alter Table students Add CONSTRAINT fk_roomalloc
      FOREIGN KEY (roomalloc)
      REFERENCES rooms(roomno);
  
      Alter table students drop constraint fk_roomalloc
  
      --ALTER TABLE STUDENTS ADD JOIN DATE
      alter table students add (joindate Date);
  
      --Alter Table for Gender
      Alter Table students add(gender varchar2(2));
      Alter Table students MODIFY gender NOT NULL;
  
      --Constraint on Gender
      Alter Table students Add CONSTRAINT gen 
      Check (gender IN('M','F','m','f'));
      Alter Table students MODIFY mess default 'M';
  
      --Constraint Gender Check for Room Allocation
      Alter Table students Add CONSTRAINTS gen_check
      Check (Room IN(Gender='M' , 'Gender='F'));
  
      --Constraints:ADD MESS AS TRUE/FALSE
      ALTER TABLE students ADD (mess varchar2(4));
      Alter Table students Add CONSTRAINT mess_present 
      Check (mess IN('Yes','No','yes','no'));
      Alter Table students MODIFY mess default 'No';
  
      --Drop Constraint
      ALTER TABLE students
      DROP CONSTRAINT mess_present
      --ALTER TABLE NAME AS NOT NULL
      alter table students MODIFY name NOT NULL;
      --ALTER TABLE PHONE NO
      alter table students MODIFY phonenum UNIQUE;
      --ALTER TABLE Room Allocated
      alter table students MODIFY roomalloc Not Null;
  
      Describe students;
  
      --DATA ENTRY and Modification
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (1, 'Haseeb', 012345678,'Rawalpindi',1,'1-sep-14','No');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate)
          VALUES (2, 'Faisal', 03451111111,'Rawalpindi',1,'12-sep-14');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate)
          VALUES (3, 'Shahbaz', 03313214567,'Khewra',1,'15-feb-15');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate)
          VALUES (4, 'Muhaddas', 01235131237,'Kashmir',1,'15-feb-15');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (5, 'Haseem', 01254530987,'Islamabad',2,'15-sep-15','Yes');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (6, 'Asim', 03341234567,'Muzzafargarh',3,'15-sep-14','Yes');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (7, 'Izza', 01231234564,'Sialkot',25,'15-sep-15','Yes');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (8, 'Sara', 01231234561,'Narrowal',25,'15-sep-15','Yes');
      INSERT INTO students(regno, name, phonenum, address, roomalloc,joindate,mess)
          VALUES (9, 'Maria', 01231234567,'Wah',4,'25-sep-15','Yes');
      INSERT INTO students(regno, name, phonenum, address,    roomalloc,joindate,Gender)
          VALUES (10, 'Faha', 0123123452,'Okara',4,'26-sep-15','F');
  
      Update students SET Gender='M' WHERE regno&gt;=1 And regno&lt;=6;
      Update students SET roomalloc=4,Gender='F' WHERE regno&gt;=7 And regno&lt;=9;
  
      Describe students;
  
      --Data Fetching Queries
  
      Select *
      From students,rooms
      Where rooms.facility='Fan/Net/TV'
      ORDER BY roomalloc , regno;
  
      Drop table students;
  
      --CREATE TABLE Rooms
      Create table rooms(
      roomno integer primary key,
      facility varchar2(30)
      );
  
      --Altering Rooms Types
      Alter Table rooms Add CONSTRAINT rtype 
      Check (facility IN('AC/Net/TV','Fan/Net/TV','Fan/Net'));
      Alter Table rooms MODIFY facility default 'Fan/Net';
  
      Alter table rooms drop constraint str
  
      INSERT INTO rooms( roomno, facility)
          VALUES (1,'AC/Net/TV');
  
      INSERT INTO rooms( roomno, facility)
          VALUES (2,'Fan/Net/TV');
  
      INSERT INTO rooms( roomno, facility)
          VALUES (3,'Fan/Net/TV');
  
      INSERT INTO rooms( roomno, facility)
          VALUES (4,'Fan/Net');
  
      Alter table rooms Modify facility UNIQUE 
  
      Select *
      From rooms;
  
      Select students.name,rooms.facility
      From students,rooms
      Where roomno=4;
  
      Drop table rooms
  </code></pre>