By Nitin on July 17, 2009
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.
Posted in Nitin's Blog | Tagged Intern, mysql
By Nitin on July 15, 2009
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:
Keep reading this post
Posted in Nitin's Blog | Tagged Intern, java, mysql, php
By Nitin on July 5, 2009
Recently while working for my project, I came across this situation when I had a 2-D array and I needed to sort it twice on 2 of its columns. Consider the following 2D array:
String[][] testString
= new String[][] {
{"1",
"2",
"6"},
{"4",
"5",
"3"}
};
Sorting the above 2D array on zero column will give
{
{"1", "2", "6"},
{"4", "5", "3"}
}
whereas sorting it on second column will give
{
{"4", "5", "3"},
{"1", "2", "6"}
}
I did not want to do the most common as well as tedious thing, i.e. write my own sorting function like this:
public void myOwnSort
(String [][] exampleArray
) {
//code for sorting the array according to my wish.
}
I wanted to avoid this for 2 resons:
- I would have to write the code for it ( lazy me!!).
- Secondly, I can possibly never match the efficiency provided by the sorting functions of java.util.Arrays
Keep reading this post
Posted in Nitin's Blog | Tagged code, Intern, java
By Nitin on May 23, 2009
Election results are out, and as I expected Congress completely overruled BJP, grabbing more than 200 seats. Do not shout that my expectations turned in favor of Congress after the election results, for proof you can ask my friends (with whom I kept fighting why BJP should not come to power!!) or just visit FriendsOfBJP where I posted several issues that were wrong in the BJP’s manifesto but unfortunately they were so confident about their views that they(supporters of BJP) kicked me out from the site (and calling me a christian, a fool, etc. )
I would like to clarify that I am not in favor of any political party, but when I have to choose I will never choose BJP over Congress for the following reasons (I am again enumerating them here not to tease the BJP supporters over their loss but so that they can improve for next elections rather than blaming media for bad publicity or congress for enjoying privileges):
Keep reading this post
Posted in Nitin's Blog | Tagged BJP, elections
By Nitin on April 14, 2009
It takes me quite a lot of time to write a post here, mainly because I have very less going on in my life at the moment. But if you were following this blog closely (I know you weren’t
), you might have noticed that I kept playing with the SHARING and BOOKMARKING tools. I started off with the bookmarkify, then tried addthis and then finally settled for tellafriend. Although, I am still thinking of shifting back to Bookmarkify, right now I am sticking with TellaFriend. As far as the features are concerned, they all almost provide the same kind of features. All of them provide access to over 50 Bookmarking sites, not to forget the “Email this” option. Here is a short review on the following Bookmarking tools.
Keep reading this post
Posted in Nitin's Blog | Tagged php, Wordpress
By Nitin on April 5, 2009
Introduction
FeedAPI Imagegrabber is a add-on module for FeedAPI. It consists of a parser which visits the original URL of a new feed item, and retrieves the main image from the post. Once the main image has been retrieved, it is then converted into a thumbnail using the ImageCache module, and stored in the node created by FeedAPI, inside a CCK field.
The purpose of FeedAPI Imagegrabber is to make the feed more informative as well as interesting for the user. As, we all know that “comics are much better than novels”, this module appends the feed-item with an appropriate image from its content URL. The goal of the module is to mimic the thumbnail display of websites such as digg.com. This goal is acheived by using FeedAPI to turn RSS feed-items into nodes, and then using FeedAPI Imagegrabber to append these nodes with an appropriate image from the feed-item’s webpage.
Keep reading this post
Posted in Drupal, Projects | Tagged Drupal, Intern, module, php