Wednesday, 22 January 2014

MySql queries

Oracle Function
http://docs.oracle.com/html/A95915_01/sqfunc.htm#i1005521

Following Link shows My sql date Format

my sql date format

You can't specify target table table name  for update in FROM clause

The above mentioned error occur when you try to execute the update statement with condition get from same table

Error Query


update employee_details set salary=10000
where salary =(select max(salary)
from employee_details be);

To solve the by using temp table

Solved Query


update employee_details set salary='10000'
where salary =(select sal from (select max(salary) as sal
from employee_details be) as temp);

 Mysql Query  Serial Number select statement


SELECT  @a:=@a+1 serial_number, 
        e.name.e,age
FROM    employee_details e,
        (SELECT @a:= 0) AS a;


MySql Show columns

SHOW COLUMNS FROM tableName where field like '%emp%';

Here field is column name of table



MySql  queries For Replace special Character into HTML tags  and   change content to  UTF8


 SELECT REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE
                                                                         (REPLACE
                                                                            (REPLACE
                                                                               (REPLACE
                                                                                  (REPLACE
                                                                                     (REPLACE
                                                                                        (REPLACE
                                                                                           (REPLACE
                                                                                              (REPLACE
                                                                                                 (REPLACE
                                                                                                    (REPLACE
                                                                                                       (REPLACE(CONVERT
                                                                                                                  (REPLACE
                                                                                                                     (REPLACE(CONVERT(columnName USING utf8),'\r\n','<br>'),' ','&nbsp;')USING 'UTF8'),':','&colon;'),'~','&tilde;'),'!','&excl;'),'@','&commat;'),'#','&num;'),'$','&dollar;'),'%','&percnt;'),'*','&ast;'),'(','&lpar;'),')','&rpar;'),'_','&lowbar;'),'+','&plus;'),'{','&lbrace;'),'}','&rbrace;'),'[','&lbrack;'),']','&rbrack;'),'^','&circ;'),':','&colon;'),'','&quot;'),'?','&quest;') AS instruction
FROM tablename

Mysql 3rd maximum salary 

SELECT e.salary
FROM salary_details e
ORDER BY empid DESC LIMIT 2,1 ;


Insert values into table, value get from  another table

insert into employee(name,age)  select name,age from master_employee;

My sql insert many row in single query
Below query is used for  insert the 3 row in single insert statement
INSERT INTO TABLE_NAME (column1,column2,column3,column4,)
VALUES 
(v1, v2,v3,v4), 
(v1,v2,v3,v4), 
(v1,v2,v3,v4);

Restart mysql

service mysql restart

Get table backup or create table with select query.
create table my_table_back
as select * from my_table;

insert  with select query.

insert into workflow.conversion_check_list_details (check_list_name, workflow_id, sas_id, product_type_id)
select instruction_name,'7' as workflow_id,'479' as sasid,'15' as product_ID from  workflow.instruction_deliverable_mapping  ind ,workflow.cfg_instruction_catalog cic where workflow_id = 17
and ind.instruction_id = cic.instruction_id
and is_prerequisite='n'
and deliverables_id = 438;

No comments:

Post a Comment