0% found this document useful (0 votes)
17 views

Lab Week 5

Uploaded by

Waleed Omar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Lab Week 5

Uploaded by

Waleed Omar
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

IT244 Introduction to Database

Week 6

1. Using the table (students) provided in the next page, provide SQL queries that retrieve
the following:

a. Students’ names and genders

b. Names of female students

c. Students who study nursing

d. Students whose name start with the letter M

e. Students in an ascending order by their names

f. Students in a descending order by their ids

g. Students whose ids are greater than 3

h. Colleges with eliminating duplicates (hint: use distinct keyword, result should
include four colleges)

2. Update the created table (students):


a. Insert the following values in the students table

id name gender collage


8 Talal Male Science

b. Modify Talal’s college to nursing instead of science.


c. Delete Talal’s information from the table.
IT244 Introduction to Database

create table students (


id integer,
name varchar (20),
gender varchar (6),
college varchar (50),
primary key (id)
);

insert into students


values(1,'Ahmed','Male','Computer Science'),
(2,'Muhammad','Male','Science'),
(3,'Maha','Female','Engineering'),
(4,'Reem','Female','Nursing'),
(5,'Khalid','Male','Engineering'),
(6,'Badr','Male','Science'),
(7,'Sarah','Female','Nursing');

--Answer

--2a
Select name, gender
From students;
--2b
Select name
From students
Where gender='Female';
--2c
Select *
From students
Where college='Nursing';
IT244 Introduction to Database

--2d
Select name
From students
Where name like 'A%';
--2e
Select *
From students
Order by name
--2f
Select *
From students
Order by id desc;

--g
Select *
From students
Where id>3;
--h
Select distinct college
From students;

--3a
Insert into students values(8,'Talal','Male','Science');
--3b
Update students
Set college='Nursing'
Where name='Talal';
--3c
Delete from students
Where name='Talal';

You might also like