Tag Archives: mysql

“What is Drupal?”, for newbies

I often come across this question from my friends and peers and most of the time I deflect it by saying “it lets you create your website easily, why don’t you look up on Wikipedia?”. Few days ago, one of my friends pointed me that most of the articles start with “Drupal is a Content Management System(CMS) …” which becomes pretty much confusing when one has no idea about what a CMS is. In this post, I have tried to explain what a CMS is and why we need it and how Drupal stands out among various other available CMSs.

Let us say you need to create a webpage for your website. Ideally, it would mean you create HTML content that will be delivered to someone who requests it through their web browser. Eventually you grow big and decide to add 100 more pages to your website and therefore create 100 more HTML pages. But then you realize that there is a lot of duplicate content. The footer which contains the copyright information is essentially the same on all pages, therefore if you ever need to edit it then it would mean to edit these 101 pages. This will be a lot of redundant work.
Continue reading

MYSQL: MINUS (Set Difference) Operator

Often we need MINUS operator as defined by the SQL definitions i.e you have two sets P and Q and you want P-Q which gives all the elements in P that are not in Q. But unfortunately, MYSQL does not have any operator for such an operation (yeah, I had the same reaction when I heard this!!).

So here is a way how you can implement it in MYSQL. For simplicity let us consider we have two tables P and Q (we can also have views, joins, etc instead of the tables here) which have atleast one column in common (say id, which usually will be the primary key) and we want to evaluate P – Q which removes all those rows from P whose id is present in Q.

Here is the SQL statement for it. The statement is quite self explanatory, but if you still have doubt then leave a comment.

Select * from P left join Q on P.id = Q.id where Q.id is NULL;

Thats is what I could think of. If you are using some better and efficient method, then please leave a comment.

MYSQL: Get the Auto-Increment Values after Insert Statement

Until sometime back, I was unaware of how I could get the value of an auto-incremented field after an Insert Statement. But recently I needed it for two of my projects simultaneously, so I explored the possibilities. As one of my project is in Java and other is in PHP, we will go through both of them.

So, here is the problem. In general, the PRIMARY KEY field is the AUTO_INCREMENT field. Now wen you insert a row, a new key is generated and you can’t get it through usual way as this row can be accessed only using the primary key.

So here is how it can be done:
Continue reading