Thursday, 23 March 2017

Sample MYSQL Query 

                           Sample MYSQL Query 



/* Create database*/

create database demoDatabase;



/* Use database*/

use demoDatabase;





/* Create Table*/




create table employee (emp_Name varchar(50),emp_salary int(11));


/* description of Table*/



desc employee;



/* Insert data in Table*/

insert into employee (emp_name,emp_salary) values('Sonu',20000);

insert into employee (emp_name,emp_salary) values('Monu',2000);

insert into employee (emp_name,emp_salary) values('gita',10000);

insert into employee (emp_name,emp_salary) values('rita',1000);

insert into employee (emp_name,emp_salary) values('Sohan',200000);

insert into employee (emp_name,emp_salary) values('priyanshu',50000);

insert into employee (emp_name,emp_salary) values('Vickys',30000);


/* get all data from table*/

select * from employee;

















/* get Maximum Salary from the Table*/



select max(emp_salary) from employee;






/* get Minimum Salary from the Table*/

select min(emp_salary) from employee;






/* get Average Salary from the Table*/

select avg(emp_salary) from employee;







/* get Sum of Salary from the Table*/

select sum(emp_salary) from employee;






select emp_Name,emp_salary from employee where emp_salary in (1000,20000);



select emp_name,emp_salary from employee where emp_salary not in (1000,20000);



/* Search name which is started from S*/

select emp_name,emp_salary from employee where emp_Name like '%S';






/* Search name which is end with S*/

select emp_name,emp_salary from employee where emp_Name like 'S%';






/* Search name which has from S*/



select emp_name,emp_salary from employee where emp_Name like '%S%';