Author: Dasun Hegoda

#1093 – You can’t specify target table ‘table_name’ for update in FROM clause

Have you ever got this MySQL error? Oh! You are searching for a solution right? You have come to the right place. Let me give you the simplest answer and it works charm.

For the time being assume that this is your query.

DELETE FROM table_name where coulmn_name IN (SELECT coulmn_name FROM table_name  WHERE coulmn_name > 10);

What you can do is change the query to something like this below.

DELETE FROM table_name where coulmn_name IN ( SELECT * FROM (SELECT coulmn_name FROM table_name  WHERE coulmn_name > 10) AS X) ;

Okay let me explain how the magic happens here.

– Read More –

How to do MySQL Indexing

MySQL Indexes! Whooh! Let me tell you what my experience about indexing a table. I had a SQL query which took 8-9 secs to fetch the data I want. After indexing now it only takes 1 sec. Interesting right. Let’s go through what’s indexing and how to and when to and stuff. You could find technical explanation of indexes in the internet. So let me elaborate it in a more appealing way to you.

Index is a pointer to the table and it allows you to retrieve the data faster. It’s the same as the index which we find in the back of a book. Index will represent the book in the keyword or subject order where book is printed in the page order. It’s true that index will faster your select query but it will slow down your other queries such as updates and inserts. You might be wondering why is that. It’s because once the new data is added to the table, Index should be updated too. Otherwise how can an index points to the new data in the table.

There are three types of indexes

  • Single Column(EG :- Indexed by mobile No)
  • Composite(EG :- Indexed by first name and last name)
  • Unique (EG :- indexed by e-mail)

Look at table below.

– Read More –

How To Reset My WordPress Admin Password?

Connect to the WordPress database via the phpMyAdmin tool at your web hosting account or open up a MySQL terminal to execute the below MySQL command.

Once in phpMyAdmin select the WordPress database & Open the SQL tab (look at the top navigation bar).

write the following SQL query:

UPDATE `wp_users` SET `user_pass` = MD5( 'new_password_here' ) WHERE `wp_users`.`user_login` = "admin_username";

 

“new_password_here” – replace this with the new password you wish to use.
“admin_username” – replace this with the username the password should be updated for.

Click on the GO button to submit the query. If everything goes fine without errors, you can login to the site using the new password.

Regular Expressions A. K. A. Regex

Let’s take a look at what’s regular expression and it’s use in the development environment. 1st of all regular expression is a small piece of code which looks for pattern(s). In web development environment Regex are used in the .htaccess file most frequently. Regexs are supposed to make developer’s life easier but most of the time it’s the other way around. Let’s stop the chit-chat and go through some technical aspects of Regexs.

– Read More –

Custom Search In WordPress For A Specific/Limited Category

Add this code where you want to put the custom search.

Settings :
action – set the site url
cat field value – should be set to the category id whatever you want to search in(here its 5)

<form method="get" id="search form" action="http://localhost/wordpress_test/">
<div>
<input type="text" value="" name="s" id="s" />
<input type="hidden" value="5" name="cat" id="scat" />
<input type="submit" value="search"/>
</div>
</form>

Yeah ! Simple as that. Try it out.

Older Posts
Newer Posts