Featured Post

What is the purpose of the php.ini file?

  The PHP configuration file,   php.ini , is the final and most immediate way to affect PHP's functionality. The php.ini file is read ea...

Showing posts with label Quick Tips. Show all posts
Showing posts with label Quick Tips. Show all posts

How to find out Max Salary from each department

You can find maximum salary for each department by grouping all records by DeptId and then using MAX() function to calculate maximum salary in each group or each department.

SQL Query:

SELECT DeptID, MAX(Salary) FROM Employee  GROUP BY DeptID.

This questions become more interesting if Interviewer will ask you to print department name instead of department id, in that case you need to join Employee table with Department using foreign key DeptID, make sure you do LEFT or RIGHT OUTER JOIN to include departments without any employee as well.  Here is the query



What is utf8_general_ci?

utf8_general_ci is a very simple — and on Unicode, very broken — collation, one that gives incorrect results on general Unicode text.
What it does is:
  • converts to Unicode normalization form D for canonical decomposition
  • removes any combining characters
  • converts to upper case
This does not work correctly on Unicode, because it does not understand Unicode casing. Unicode casing alone is much more complicated than an ASCII-minded approach can handle. For example:

Global variables of Drupal 7

Scope can be defined as the range of availability a variable has to the program in which it is declared. PHP variables can be one of four scope types:
  1. Local variables
  2. Function parameters
  3. Global variables
  4. Static variables.
Global Variables:
In contrast to local variables, a global variable can be accessed in any part of the program. However, in order to be modified, a global variable must be explicitly declared to be global in the function in which it is to be modified. This is accomplished, conveniently enough, by placing the keyword GLOBAL in front of the variable that should be recognized as global. Placing this keyword in front of an already existing variable tells PHP to use the variable having that name.
Here are the list of Drupal Global Variables:

How to display the SQL query in Drupal 7 views?

When working in the Views module, you may want to preview the SQL that is generated by the view. This is for the code savvy or the ones looking to be and would like to see the SQL generated for either debugging or further development of their views. Sometimes seeing the code can help understand how the view works in case it needs further tweaking. Showing the SQL query for a View's preview is done with the following instructions.

What is RDBMS ?

Relational Database Management system (RDBMS) is a database management system (DBMS) that is based on the relational model. Data from relational database can be accessed or reassembled in many different ways without having to reorganize the database tables. Data from relational database

Drupal multi-site Drush aliases configuration

If you're running a multi-site Drupal setup, here's how to set up your Drush aliases to easily run commands for specific sites:
1.Go to drush installed directory cd /home/XXX/.drush
2. Create file aliases.drushrc.php, add the below code for multi-site aliases

How to find the top 2 salaried employees in each department

Let us take the table having different departments

Table Name:-  employee

+------+------------+------------+--------------+
| id   | dept_name  |  emp_name  |      salary  |
+------+------------+------------+--------------+
|    1 | ECE        | Raj        |        10000 |
|    2 | ECE        | Ravi       |        12000 |
|    3 | ECE        | Malli      |        14000 |
|    4 | CSE        | Madhav     |        12000 |
|    5 | CSE        | Jaani      |        14000 |
|    6 | CSE        | Jack       |        15000 |
|    7 | IT         | Mill       |        16000 |
|    8 | IT         | Pawan      |        17000 |
|    9 | IT         | Jack       |        18000 |
+------+------------+------------+--------------+
 
From above table for top 2 salaried employees see below query

Popular Posts