<< BACK
Query :
Create Database :
create database databaseName
select user_name,user_email from user_details
select count(*) from user_details where user_name = 'Rajesh'
SELECT e.emp_name, u.user_name FROM emp_details AS e JOIN user_details AS u ON e.emp_id = u.user_id
select * from tableName where section_id REGEXP '[[:<:]](7)[[:>:]]'
Query :
Create Database :
create database databaseName
Create Table :
CREATE TABLE `user_details` (
`user_id` int(11) NOT NULL AUTO_INCREMENT,
`user_name` varchar(2000) DEFAULT NULL,
`user_email` varchar(2000) DEFAULT NULL,
`user_number` varchar(2000) DEFAULT NULL,
`user_dob` date DEFAULT NULL,
`gender` varchar(2000) DEFAULT NULL,
`address` text,
`ip` varchar(100) DEFAULT NULL,
`upload_date` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
PRIMARY KEY (`user_id`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=latin1;
Drop Table :
DROP TABLE `user_details1`;Insert Data :
insert into `user_details`(`user_id`,`user_name`,`user_email`,`user_number`,`user_dob`,`gender`,`address`,`ip`,`upload_date`) values (1,'Rajesh','rajeshpalande77@gmail.com','9221460041','1988-12-07','Male','test',NULL,'2015-08-26 13:16:11');Show All Data :
select * from user_detailsShow Record Base On Key :
select user_name from user_detailsselect user_name,user_email from user_details
Fetch Record By Using Where Clause :
select * from user_details where user_id = '1'Delete Record By Using Where Claise :
delete from user_details where user_id= '3'Update Record :
update user_details set user_name = "Ramesh" where user_id = '2'Count :
select count(*) from user_detailsselect count(*) from user_details where user_name = 'Rajesh'
Update Record :
select max(*) from user_detailsMax :
select min(*) from user_detailsJoin :
u ,e is objectSELECT e.emp_name, u.user_name FROM emp_details AS e JOIN user_details AS u ON e.emp_id = u.user_id
Unique Record :
select DISTINCT user_email from user_detailsAscending Order :
select * from user_details order by user_name ascDescending Order :
select * from user_details order by user_name descLimit :
select * from user_details limit 1Order + Limit :
select * from user_details order by user_name desc limit 1Like(Search Last Word) :
select * from user_details where user_name like '%esh'Like(Search First Word) :
select * from user_details where user_name like 'raj%'Like(Search Any Word) :
select * from user_details where user_name like '%ra%'Group By :
SELECT emp_name, Max(age) FROM emp_details GROUP BY emp_nameAlter (Add Columns) :
ALTER TABLE emp_details ADD DateOfBirth dateAlter (Delete Columns) :
ALTER TABLE emp_details DROP COLUMN DateOfBirthAlter (Table Name) :
ALTER TABLE TableOldName RENAME TableNewNameGet result from multiple Value in column :
e.g. my column name is section_id and value of this section id is 7,17,27,37 and I want to find result of matching only number 7, not (17,27,37) then use following queryselect * from tableName where section_id REGEXP '[[:<:]](7)[[:>:]]'
No comments:
Post a Comment