Tuesday, July 29, 2014

Find second largest value / Salary using Mysql

Using Sub query

Option Query 1

  SELECT MAX(salary) FROM emp WHERE salary NOT IN
 (SELECT MAX(salary) FROM emp)


Option Query 2


     SELECT MAX(salary) FROM emp WHERE salary <(SELECT MAX(salary) FROM emp)

Option Query 3
    SELECT MIN (salary) FROM emp WHERE salary in (SELECT TOP 2 (salary) FROM emp ORDER BY salary DESC)

Monday, July 28, 2014

Difference between parent() vs parents()

Below code clarify some differences between the parent() and parents() methods.

parent(selector) : This returns the one immediate parent of the element. Selector is passed in only required cases, like if we want to check if parent exists for the element or in some other situations. Here is simple example which illustrates the parent method.



parents(selector) : This returns the multiple ancestors. Its not restricted to only one level of parent/ancestors of the element. This is the main difference between the parent and parents method.

For Examples 1
<html>…<body><div class=”one”><div class=”two”><p><span>Some text</span></p></div></div></body></html>

$(‘span’).parent() will select the <p> tag such that the element set in the jQuery object is [span].

$(‘span’).parents() will select all parent tags such that the element set in the jQuery object is [p, div.two, div.one, body, html].

So parent() will select the first parent element while parents() will select all elements straight up the DOM tree.

The .parents() and .parent() methods are similar, except that the latter only travels a single level up the DOM tree. Also, $( "html" ).parent() method returns a set containing document whereas $( "html" ).parents() returns an empty set.


For Examples 2


HTML Code

<!DOCTYPE html>
<html lang="en">
  <head>
     <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
  </head>
  <body>
     <div>
        <p>
            <a href="#" id="anchorTag">Click here</a>
         </p>
      </div>
   </body>
</html>


jQuery  For parent()
   $('#anchorTag').parent();      //This would return p, immediate parent of a#anchorTag.


jQuery  For parents()
   $('#anchorTag').parents();        //This would return all the ancestors (p, div, body, html)

   //On passing selector it will filter down the matched parent elements by selector

   $('#anchorTag').parents('div');   //This would give me only div




 closest(selector) : It works like parents(), except that it returns only one parent/ancestor. This is ideal for the situation i mentioned earlier. If i want to check for existence of element in the ancestry tree, then i would prefer to use the closest rather than parents as it only target the selector rather than filtering it from all the ancestor elements. Here is example

$('#anchorTag').closest();           //This would give me empty object as we have not mentioned the selector
$('#anchorTag').closest('div');      //This would give me the div.

Tuesday, July 22, 2014

Extract XML Data using JavaScript

This code is very useful Extract XML Data using JavaScript.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Extract XML Data using JavaScript </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head>
        <title>Extract XML Data using JavaScript</title>

        <style>
            #books
            {
                font:13px Arial;
                width:590px;
                text-align:center;
                border:solid 1px #000;
                overflow:hidden;
            }
            #books div
            {
                width:180px;
                text-align:left;
                border:solid 1px #000;
                margin:1px;
                padding:2px 5px;
            }
           
            .col1 {float:left;clear:both;}
            .col2 {float:left;}
 .col4 {float:right;}
           
        </style>
    </head>
<body>
    <div id="books"></div>
       
    <script type="text/javascript">

        var oXHR = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

        function reportStatus() {
            if (oXHR.readyState == 4)               // REQUEST COMPLETED.
                showTheList(this.responseXML);      // ALL SET. NOW SHOW XML DATA.
        }

        oXHR.onreadystatechange = reportStatus;
       
        oXHR.open("GET", "lib.xml", true);     
                    // true = ASYNCHRONOUS REQUEST (DESIRABLE), false = SYNCHRONOUS REQUEST.
        oXHR.send();

        function showTheList(xml) {

            var divBooks = document.getElementById('books');        // THE PARENT DIV.
            var Book_List = xml.getElementsByTagName('List');       // THE XML TAG NAME.

            for (var i = 0; i < Book_List.length; i++) {

                // CREATE CHILD DIVS INSIDE THE PARENT DIV.
                var divLeft = document.createElement('div');
                divLeft.className = 'col1';
                divLeft.innerHTML = Book_List[i].getElementsByTagName("BookName")[0].childNodes[0].nodeValue;

                var divRight = document.createElement('div');
                divRight.className = 'col2';
                divRight.innerHTML = Book_List[i].getElementsByTagName("Category")[0].childNodes[0].nodeValue;




     var divRightnew = document.createElement('div');
                divRightnew.className = 'col4';
                divRightnew.innerHTML = Book_List[i].getElementsByTagName("Price")[0].childNodes[0].nodeValue;


                // ADD THE CHILD TO THE PARENT DIV.
                divBooks.appendChild(divLeft);
                divBooks.appendChild(divRight);
                     divBooks.appendChild(divRightnew);
            }
        };

    </script>
</body>
</html>



After create xml file "lib.xml" 
<?xml version="1.0"?>
<!--  Last edited by http://encodedna.com  -->
<Library>
    <List>
        <BookName>Computer Architecture</BookName>
        <Category>Computers</Category>
        <Price>125.60</Price>
    </List>
    <List>
        <BookName>Advanced Composite Materials</BookName>
        <Category>Science</Category>
        <Price>172.56</Price>
    </List>
    <List>
        <BookName>Asp.Net 4 Blue Book</BookName>
        <Category>Programming</Category>
        <Price>56.00</Price>
    </List>
    <List>
        <BookName>Stategies Unplugged</BookName>
        <Category>Science</Category>
        <Price>99.99</Price>
    </List>
    <List>
        <BookName>Teaching Science</BookName>
        <Category>Science</Category>
        <Price>164.10</Price>
    </List>
    <List>
        <BookName>Challenging Times</BookName>
        <Category>Business</Category>
        <Price>150.70</Price>
    </List>
    <List>
        <BookName>Circuit Bending</BookName>
        <Category>Science</Category>
        <Price>112.00</Price>
    </List>
    <List>
        <BookName>Popular Science</BookName>
        <Category>Science</Category>
        <Price>210.40</Price>
    </List>
    <List>
        <BookName>ADOBE Premiere</BookName>
        <Category>Computers</Category>
        <Price>62.20</Price>
    </List>
</Library>


Wednesday, July 2, 2014

List Of Mysql Queries Used any Programming Language

Following  Mysql Queries  Used In Php

  • mysql_query
  • mysql_fetch_array
  • mysql_fetch_assocs
  • mysql_fetch_row
  • mysql_fetch_object
  • mysql_close
  • mysql_fetch_field
  • mysql_fetch_leanth
  • mysql_fetch_affected_rows
  • mysql_connect
  • mysql_pconnect
  • mysql_select_db
  • mysql_create_db
  • mysql_data_seek
  • mysql_db_name
  • mysql_db_query
  • mysql_drop_db
  • mysql_error
  • mysql_field_flags
  • mysql_field_len
  • mysql_field_table
  • mysql_field_type
  • mysql_field_seek
  • mysql_free_result
  • mysql_insert_id
  • mysql_first_dbs
  • mysql_list_field
  • mysql_ping
  • mysql_hum_field
  • mysql_read_escape 
Please click here more Info