Tuesday, 1 August 2017


Given a table SALARIES, such as the one below, that has m and f values. Swap all f and m values with a single update query and no intermediate temp table.


Id Name Sex Salary 1 A m 2500 2 B f 1500 3 C m 5500 4 D f 500


UPDATE SALARIES SET sex = CASE sex WHEN 'm' THEN 'f' ELSE 'm' END



Friday, 28 July 2017

To Create a View of Table


CREATE VIEW name_view AS SELECT column1, column2, column3.... FROM tablename

Monday, 8 August 2016

Find out nth order salary in MySQL

To find out the nth highest salary from employee table :
SYNTAX:

SELECT * from employee emp WHERE (n) = (SELECT COUNT(emp2.salary) FROM employee emp2 WHERE emp2.salary >= emp.salary)
where n is the number of salary which you want.

OR

To Find the 2nd Highest Salary in following ways



SELECT name, salary FROM employee where salary NOT IN (SELECT MAX(salary) from employee)

SELECT MAX(salary) FROM employee where salary NOT IN (SELECT MAX(salary) from employee)
SELECT DISTINCT salary FROM employee ORDER BY salary DESC LIMIT 1,1;

Send Mail via PHP

Send an Email via PHP
Step 1: Create the form for an Email



<form action="mail_send.php" method="post" name="email">
<table width="354" height="279" >
<tr><td>To:</td><td><input type="email" name="to" value="" />
</td></tr>
<tr><td>From Name:</td><td><input type="text" name="name" value="" />
</td></tr>
<tr><td>Subject:</td><td><input type="subject" name="subject" value="" />
</td></tr>
<tr><td>From Email:</td><td><input type="email" name="femail" value="" />
</td></tr>
<tr><td colspan="2"><input type="submit" name="submit" value="SEND" />
</td></tr>
<tr><td>Message:</td><td><textarea cols="20" name="message" rows="8">
</textarea></td>
</tr>
</table>
</form>
Step 2: Write the php script for email


<?php 
if(isset($_POST[femail])){
    $to = $_POST["to"];
    $femail = $_POST["femail"];
    $name = $_POST["name"];
    $subject = $_POST["message"];
    $message = wordwrap ($message, 70);
    mail($to, $subject, $message, "From: $femail\n");
    echo "Thank you for sending a mail";
}else{
    echo 'mail not send..!!';
}
?>


Wednesday, 3 August 2016

Make dropdown as a required field in HTML5

If you want to make <select> field as a required field then you have to do like this
<select name="" required x-moz-errormessage="Please Select the Field">
<option value="">Select the Field</option>
<option value="One">One</option>
<option value="Two">Two</option>
</select>