Find 2nd Largest Value Using SQL

We all know that the MAX function can be used to find the largest value in SQL. How, then, can we write a single-pass SQL that can be used across different database systems to find the second largest value in a column? Single-pass means only one SQL query gets executed, as opposed to having multiple SQL statements using temporary tables to store intermediate results.

Continue reading

Find Duplicates in SQL

SQL does not provide a built-in capability to find duplicates in a table. Fortunately, it is fairly easy to write a SQL query that does it. The idea is to count the number of occurrences for each value, and then use the HAVING condition to show only the values that appear more than once.

SELECT COLUMN_NAME, COUNT(*)
FROM TABLE_NAME
GROUP BY COLUMN_NAME
HAVING (COUNT(*) > 1);

Continue reading

File Transfer Between Android and PC

There are many occasions when we want to transfer files between our Android device and our PC. One way to do this is to connect the Android device to the PC via a USB cable. On the other hand, sometimes this does not work for a variety of reasons. Below I describe how I set up my Android and PC so I can transfer files between them.

File transfer from Android to PC

I use Bluetooth for this, and there are two components: Hardware and software. On the hardware side, you’ll want to make sure your PC is Bluetooth-ready. My PC did not have Bluetooth capabilities, so I bought a Bluetooth adapter (IOgear IOGBU421) to make sure my PC can communicate via Bluetooth. On the software side, I used Bluetooth OBEX File Transfer from Medieval Software. I downloaded and installed the PC version, and then I downloaded and installed the Android app version to my Android phone. Both versions are free. Once installations are complete, start the app in Android, and then open the file transfer program in PC. You’ll be able to connect to your Android device and download the files from your Android device.

Continue reading

Copy a table in SQL

In a relational database, sometimes there is a need to copy a table in SQL. This post talks about several different scenarios on doing this, and how to use SQL to accomplish each scenario.

Copy a table with all data

To copy a table with all the data, simply create a new table and populate the table with SELECT * from the original table. This will copy over the table structure as well as all the data that was in the original table.

The syntax you would use is

CREATE TABLE TABLE_NAME_2
SELECT * FROM TABLE_NAME 1;

Please note that this will not copy over the constraints or indexes associated with this table.

Continue reading

DNS Changer Malware and July 9, 2012

There’s a lot of discussion on the DNSChanger malware, with some articles using eye-catching headlines such as “malware may knock thousands off Internet on Monday.” I did some research on this topic and below are the facts around this malware.

What is DNS Changer

The DNSChanger malware was created in 2007. The affected computers had their DNS settings altered so that everytime that computer access the internet, it uses cybercriminal’s DNS server. The end result was that users would see unwanted ads, as well as being redirected to sites that were not their intended targets.

Continue reading

New Cyber Threat: Flame/Flamer/Skywiper Virus

Over the weekend, reports surfaced about a new malware called Flame (some called it Flamer, and some others called it Skywiper). Within a short period of time, all top antivirus vendors, for example Symantec, Kaspersky, and McAfee, published information on this malware. So far, this virus has been found to affect Windows machines, and it has been detected mostly in the Middle East.

The details on this threat, despite the scrutiny, are not 100% clear. What is known is that it is 20MB, a huge size for a threat. The reason it’s so large is because it has many different modules. The sheer size means that it will likely take antivirus vendors a long time to fully analyze Flame.

Continue reading

Download Pictures From Your Feature Phone Via Bluetooth

I have a feature phone that I took some pictures with, but there wasn’t an easy way for me to download those pictures to my computer. I’ve always thought that I’d figure out a way to do this, but never got to it. A few days ago I was finally able to do it via the following steps:

1. My feature phone has Bluetooth capabilities, so I figured a good path to go is to give my computer Bluetooh capability by purchasing a Bluetooth USB device. There are several you can find if you search for “USB Bluetooth.” The one I got was IOGEAR USB 2.1 Bluetooth Micro Adapter.

Continue reading

Check Server Load On Shared Host Using PHP

If you are using a shared hosting plan to host your website, chances are that you are sharing the same server with hundreds, and maybe even thousands, of other domains. Does this lead to performance issues? Quite possibly. But how do you check for that? Many hosting companies will post server status, but all that really gives you is whether the server is up or down. Server status does not tell you what’s the load on the server.

Continue reading