SELECT COMMAND
1-Simple display
2-Conditional display
3-Between operator
4-In Operator
5-IS NULL Operator
6-Like Operator
7-Logical operator(and , or, not)
8-Distinct operator, Aggregate functions
9-Order by Cause
10- Group by clause
Between Operator: It is used to specify range in the condition.
Ques: Display details of all students who scored between 70-90
Ans:
FROM STUDENT WHERE MARKS BETWEEN 70 AND 90;
or
SELECT * FROM STUDENT WHERE MARKS>=70 AND MARKS<=90;
IN Operator: It is used to specify list of values in the condition.
Ques: Display details of all the students of Class 7,9and 11.
Ques: Display details of all students of Del, Kan and Agra.
IS NULL Operator: It is used to check the absence of
values.
Ques: Display details of all the students whose city is not
known.
Ques: Display details of all the students whose marks is not
known.
Logical operator(not): It is used to reverse the condition.
Ques: Display details of all students whose marks are not
known.
Ques: Display details of all students whose city is known.
Like Operator- It is used for pattern matching and makes
use of two characters:
1) _(Underscore): Single character, any character
2) %(Mod): Zero or more character, any character.
Example:
1) S_N: SIN, SON, SUN, SKY, SOON, SEEN
2) S_ _ N: SIN, SINK, SEEN, SOON,SING, SPIN
3) S%N: SIN, SOOON, SPIN,SING, SIGN, SPOON, SPLEEN,
SUN,SON
Ques: Display details of all students whose name begin
with letter S.
Ans: SELECT * FROM STUDENT WHERE NAME LIKE 'S%';
Ques: Display details of all students whose name ends
with letter N.
DISTINCT OPERATOR: It is used to filter out the duplicate
values from the specified field.
Aggregate Functions: These are predefined functions operates
on multiple rows/values.
Ex: Count(), Min(), Max(), Sum(), Avg().
Ques: Display total no. of students in the table.
Ques: Display total no. of students in class 11;
Sol: Select count(*) from student where class=11;
Ques: Display total no of students whose marks are not
known.
Sol: Select count(*) from student where marks is null;
ORDER BY CLAUSE: This clause is used with select command to
arrange the details in ascending or descending order. The
default order is ascending, to change the order DESC keyword
is used.
Syntax:
SELECT <fields> FROM <Table> [WHERE] [ORDER BY] [GROUP BY];
Note: elements specified in <> brackets are compulsory to specify,
whereas elements in [] are optional.
Ascending Order.
Descending Order
Ques: Display details in alphabetical order of name.
Ques: Display details in reverse alphabetical order of name.
Ques: Display details of class 11 students in descending order of
marks.
Sol: SELECT * FROM STUDENT WHERE CLASS=11 ORDER BY MARKS
DESC;