-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFirstSQLTable_student.sql
More file actions
121 lines (85 loc) · 2.95 KB
/
Copy pathFirstSQLTable_student.sql
File metadata and controls
121 lines (85 loc) · 2.95 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
create database riuf;
use riuf;
create table student(
rollno int,
stdname varchar(255),
age int,
city varchar(255),
);
--insert into table name not database
insert into student(rollno,stdname,age,city)
values(1,'Nayyab',20,'Faisalabad');
insert into student(rollno,stdname,age,city)
values(2,'Laiba',21,'Lahore');
insert into student(rollno,stdname,age,city)
values(3,'rubab',22,'Lahore');
insert into student(rollno,stdname,age,city)
values(4,'namra',23,'Faisalabad');
insert into student(rollno,stdname,age,city)
values(5,'saliha',24,'islamabad');
insert into student(rollno,stdname,age,city)
values(6,'orwa',24,'karachi');
insert into student(rollno,stdname,age,city)
values(7,'ayesha',25,'multan');
insert into student(rollno,stdname,age,city)
values(8,'nabia',26,'sialkot');
insert into student(rollno,stdname,age,city)
values(9,'muniba',27,'pindi');
insert into student(rollno,stdname,age,city)
values(10,'rafia',27,'sindh');
--to display all the result in table form
select *from student;
--to display particular data within particular column like different students with different ages
select distinct age from student;
use riuf;
select *from student;
--to display different required column not all (it displays the students with different rollno)
select rollno, stdname from student;
--to display particular different data within particular column
select distinct city from student;
--Conditional statement
select stdname from student
where age=20;
select rollno from student
where city = 'lahore';
select *from student
where age>20;
-- use keyword (order by) for arranging in ascending order
select *from student
order by age;
--using keyword desc or asc
select *from student
order by age desc;
select *from student
order by city;
--AND operator--
select *from student
where city = 'lahore' AND Age='21'; --here both conditions will be true
select *from student
where city = 'lahore' AND Age='27'; --here one condition is not true so the result will not be displayed
select *from student
where city = 'lahore' AND Age>'21';
--OR operator--
select *from student
where city = 'lahore' OR Age='20'; --here if only one condition will be true so the result will be displayed
select *from student
where stdname = 'nayyab' OR Age='20';
select *from student
where stdname = 'nayyab' OR Age= '20' OR city= 'Faisalabad';
--Not operator--
select *from student
where NOT Age='24';
select *from student
where NOT city='lahore';
-- IN operator used to select or display multiple data within same column (compare a single column to multiple values)
select *from student
where city IN ('Lahore' , 'faisalabad' );
-- not in operator
select *from student
where stdname NOT IN ('orwa','laiba');
-- between operator
select *from student
where (age between 20 AND 24);
-- not between operator
select *from student
where age NOT between 20 AND 24;