Thursday, April 5, 2012

CASE WHEN option in MySQL

MySQL will return conditional based values without using if condition. Without using if conditions, we can use CASE WHEN option in MySQL.

For example,

For example: table name: students
snonamemark
1Sachin39
2Dravid90
3Kohli30
4Ganguly66
Output: Pass mark is above 40
snonameresult
1SachinFail
2SachinPass
3KohliFail
4GangulyPass
Query:
SELECT sno, name, CASE WHEN  mark >= 40 THEN 'Pass' ELSE 'Fail' END AS Result FROM student

Wednesday, March 28, 2012

Pass the form values from one domain to another domain with POST values.

yes. we can pass the form values from one domain to another domain with using POST method. We have to add action attribute in <form> tag.
<form method="POST" action="http://www.anotherdomain.com" target="_parent">
</form>

Tuesday, March 27, 2012

Restrict cut, copy and paste in text area using Jquery

HTML:
<textarea id="textarea_id" > </textarea>
Script:

$(document).ready(function() {
$('#textarea_id').bind('cut copy paste', function(e) { e.preventDefault(); });
});

Remove or Delete duplicate records in a table in MySQL

Remove the duplicate records in a table, it will delete records which is having greater than the sno

For example: table name: players

snonamecoach_id
1Sachin1
2Sachin5
3Kohli1
4Ganguly2
5Kohli4
6Gambir3

Query:
DELETE FROM players USING players , players AS virtualtable
WHERE players .sno > virtualtable.sno
AND players .name = virtualtable.name

Output:
snonamecoach_id
1Sachin1
3Kohli1
4Ganguly2
6Gambir3

Display limited records with out using LIMIT in MySQL

If you want to get display limited records with out using LIMIT option in MySQL.
For example: table name: players

snonamecoach_id
1Sachin1
2Dravid5
3Kohli1
4Ganguly2
5Sehwag4
6Gambir3

Query:
SELECT one.sno, one.name FROM players AS one
WHERE ( SELECT COUNT(*) FROM players AS two WHERE two.sno <= one.sno ) <= 3

Output:
snonamecoach_id
1Sachin1
2Dravid5
3Kohli1