Category Archives: Nitin’s Blog

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

Sorting a 2-Dimensional Array in Java

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:

  1. I would have to write the code for it ( lazy me!!).
  2. Secondly, I can possibly never match the efficiency provided by the sorting functions of java.util.Arrays

Continue reading

Election 2009: Congress won or BJP lost?

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):

Continue reading

Sharing and Bookmarking Tools

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.
Continue reading

Schengen Visa to Germany

Note: The procedure given happened to me, I do not guarantee you the same, may be I was lucky or you will be.

I leave the details of the trip (tiring but exciting) for my next post, and will try to outline the procedure to get the Schengen Student Visa for Internship from German Consulate at Kolkata. I specifically mentioned Kolkata because my friends faced quite a lot of problems at the Delhi Embassy.

So you start with your documents, here is the list:
Continue reading