mysql concat function alias sql example - concatenating two or more strings to a single

mysql concat function alias sql example - concatenating two or more strings to a single

Before running this example please make a database hr which can be found: click here to garb the script

mysql-concat-function-alias-sql-example.php


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
 <head>
  <title>mysql concat function alias sql example - concatenating two or more strings to a single</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
  <meta name="Author" content="Md Iqbal Hosan">
  <meta name="title" content="mysql concat function alias sql example - concatenating two or more strings to a single">
  <meta name="keywords" content="php, example, code, table, sql command, sql,mysql concat function, alias">
  <meta name="description" content="mysql concat function alias sql example - concatenating two or more strings to a single">
  <style>
   h2, h4{background:#eee; color:#000087;}
   h2{ padding:3px; margin:3px; font-size:22px;}
   h4{ padding:2px; margin:2px; font-size:19px;}
   p{padding:2px; margin:2px; color:#0099Fd;}
   body{ background:#FFFFFb;}
  </style>
 </head>
 <body>
  <h2>mysql concat function alias sql example - concatenating two or more strings to a single</h2>
  <pre>
   <?php
    /*
     -----------------------------------------------------------------------------------------------
     so we have a table named EMPLOYEES in the HR database and we would like to get the value of
     FirstName AND LastName concatenated to a single value and also renamed the heading using alias
     by using mysql concat function and sql alias.
     -----------------------------------------------------------------------------------------------
    */
    $sql = "SELECT concat(FirstName, LastName) AS FullName FROM employees";
    /*
     ----------------------------------------------------------------------------------
     note that CONCAT() function returns NULL if any of the given argument(s) is NULL.
     ----------------------------------------------------------------------------------
    */
    /*
     -------------------------------------------------------
     USING PHP YOU CAN DO THIS. 
     GET CONNECTION TO DATABASE BY USING : mysql_connect()
     SELECT DATABASE BY USING : mysql_select_db()
     THEN RUN THE QUERY
     -------------------------------------------------------
    */
    

    mysql_connect('localhost', 'root', 'root');
    mysql_select_db('hr');
    mysql_query($sql);
    
    /*
     ------------------------------------------------------------------------------
     TO RUN THE PHP CODE PROVIDE REAL DATA TO mysql_connect AND mysql_select_db()
     ------------------------------------------------------------------------------
    */
   ?>
  </pre>
 </body>
</html>

mysql concat function alias sql example - concatenating two or more strings to a single - output in the client

No comments:

Post a Comment

leave your comments here..