Use where clause at the end in joins

The result of the below 2 queries are different:

SELECT u.user_name FROM user u left join sales_people sp on where sp.profit=” and u.user_name like ‘%test%’ GROUP BY

SELECT u.user_name FROM user u left join sales_people sp on and sp.profit=” where u.user_name like ‘%test%’ GROUP BY

In the first query, we have the sequence: join, on, where, and
In the second query, we have the sequence: join, on, and, where

It is always recommended to use the second method of forming join queries, putting where clause at the last.
This way, we will get correct results.


Use in clause at the end in sub queries

The query (0.0020 sec):

SELECT u.user_name FROM user u where u.user_name like ‘%test%’ and in (select user_id from user_role) GROUP BY

is faster than the below query (0.0060 sec):

SELECT u.user_name FROM user u where in (select user_id from user_role) and u.user_name like ‘%test%’ GROUP BY

Reason could be due to the filtration of users by username, before doing the in() check.
So better put ‘in’ condition at the last.


wordpress update url database

Did you ever wished to change the URL for your wordpress site, or you have copied all files and database of a wordpress site to another site, and you wanted to change the URLs for the new one?

Below are the steps to be followed, to update the url settings of a wordpress site.

Step 1: Run the below queries in the database, to replace all the old URLs with new URLs:

Step 2 (Optional): Edit wp-config.php file to add the below lines to it, defining the new URL:



overlay div css example

The below example implements a div overlay on another div, by calculating the position, width and height of the first div, with jquery.

Here is a Demo.


jsonp ajax call jquery

Normally jquery ajax does not permit making cross domain requests.
So if we are on site A, we cannot make an ajax call to a page on site B, to get a json response.

This limitation is solved by using jsonp call of jquery ajax, specifying a callback function at both the sides.

Below is an example of making a jsonp call using jquery ajax.

The server side code must send ajax json response as a callback function, like:

Then the caller ajax code should implement the callback function:

Then loop over the json response, in the callback function:

Reference: Here


drupal display errors

In Drupal, normally we don’t see errors in the front end. But there might be few errors hiding here and there, which we would like to check during development phase.

For this purpose, it is easy to turn on error reporting with the below code. Place it in sites/default/settings.php:

Courtesy: Reference

Note: As a security measure, it is recommended to give the permissions of 0444 for the settings.php file. So if you change anything in the file, don’t forget to revert back its permissions to 0444.


Online Web Tutorials