Wednesday, 3 August 2016

INNER JOIN of two tables

if you have two tables like product and product_description  and you want the inner join of these tables then the query will be like this:
select product.model, product_description.name, product.price, product.weight, 
product_description.description from product INNER JOIN product_description on
product.product_id=product_description.product_id

Tuesday, 2 August 2016

ADD Foreign Key in existing Table

How to add Foreign Key in existing table
if you want to add any column as a foreign key in your existing table then you have to write following MySQL query for that
Syntax:
ALTER TABLE tablename ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
if you want to add multiple column as a foreign key in the same table then you have to write the following MySQL query:
Syntax:
ALTER TABLE tablename 
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)
ADD CONSTRAINT FOREIGN KEY column_name REFERENCES ref_table_name(column_name)

Confirm before DELETE the record by javascript

<script type="text/javascript">
function ConfirmDelete() {
if (confirm("Delete Account?"))
location.href='linktoaccountdeletion';
}
</script> echo '<input type="button" onclick="ConfirmDelete()" value="DELETE ACCOUNT">';

File Upload Validation using javascript

Below are the script by which you can validate file when you upload
Make the form
<form>
<div class=”form-level“>Upload Resume
<input name=”image” type=”file” id=”upload_resume” placeholder=”Upload Resumeclass=”form-control” /></div>
</form>
var fup = document.getElementById('upload_resume'); 
var fileName = fup.value;
var ext = fileName.substring(fileName.lastIndexOf('.') + 1);
if(ext == "doc" || ext == "docx")
{
return true;
}
else
{
alert("Please select your Resume. Only pdf, doc and docx files are accepted");
fup.value="";
fup.focus();
return false;
}
}

3rd Highest Salary from employee table

SELECT * FROM employee one1 WHERE ( 3 ) = ( SELECT COUNT( one2.emp_salary ) FROM employee one2 WHERE one2.emp_salary >= one1.emp_salary )