Method:3
To display all columns and selected rows
In order to display selected records/rows we have to apply a condition. In SQL the condition is specified using “where” clause.
Syntax:
Select * from tablename where condition;
Example:
Select * from std where roll=500;
Select * from std where roll>=100;
Select * from std where name=’amit’;
Method:4
To display selected columns and selected rows
Syntax:
Select col1,col2,col3
from tablename
where condition;
Examples:
Consider the following tables:
Table name | Attributes |
Std | Roll,Name,age |
student | Roll,Name,m1,m2,m3,total,per |
Bank | Accno,Name,Bal,Bname,City |
emp | Empno,Name,Deptno,deptname,Desig,Sal |
product | Pno,Name,Rate,qty,cost |
Query:1
Display roll and name of all the students who can vote?
mysql>Select roll,name from std where age>=18;
Query:2
Display name of all the students who cannot vote?
mysql>Select name from std where age<18;
Query:3
Display roll number of Amit?
mysql>Select roll from std where name=’Amit’;
Query:4
Display name of all the students whose roll number is in 3 digits
mysql>Select name from student where roll>=100 and roll<=999;
Query:5
Display name of all the students who have got 1st division.
mysql>Select name from student where per>=60;
Or
mysql>Select name from student where (m1+m2+m3)/3>=60;