Class 12 | MySQL 8

To display/view the data present in table

Command: Select
This command Helps us to display the records of an existing table.

Select command can be used in following ways.

(i) To display all rows and all columns
(ii) To display selected columns and all rows
(iii) To display all columns and selected rows
(iv) To display selected columns and selected rows

Method:1
To display all rows and all columns

Syntax:
Select * from tablename;

Example:
Select * from std;
Select * from emp;
Select * from product;

Method:2
To display selected columns and all rows

Syntax:
Select col1,col2,col3 from tablename;

Example:1
Table:std(roll,name,age)

Select roll,name from std;
Select name , roll from std;

Example:2
Table:Student(roll,name,m1,m2,m3,total,per)

Create table student(roll int,name char(20),m1 decimal,m2 decimal,m3 decimal,total decimal,per decimal);

Insert into student values(102,’abc’,98,90,97,null,null);

Select roll,name,m1,m2,m3,m1+m2+m3,(m1+m2+m3)/3 from student;

Select roll,name,m1,m2,m3,m1+m2+m3 total ,(m1+m2+m3)/3 per from student;