Learning about SQL has been simple so far, but I’m sure it gets much more complicated. The challenging parts for me are when multiple subqueries are involved.
One thing I learned that I found interesting is that you can use inequality statements in a SQL join. At first it seems like a strange concept, but like most things it’s easier when you think of an example in real life.
If you some kind of on foot canvasing, like a political campaign or door-to-door sales, it is not unlikely that you’ll end up with duplicate “sign ups”. At the of your canvasing, it would be a good idea to find and remove any duplicate entries. Maybe someone thought they were being helpful by signing your petition twice, or wanted another month of cheap cable. No matter the reason, we want to clean up our data and remove unnecessary entries.
By asking the computer to list the address and name of entries that match with ID values that do not match, you can find the ID of repeat entries in your database. Here is an example SQL snippet that I would use in a similar case.
SELECT su1.id, su1.address, su1.name,
su2.id, su2.address, su2.name
FROM signups su1
JOIN signups su2
ON su1.address = su2.address
AND su1.name = su2.name
AND su1.id < su2.id
This would give you a resulting table that looks something like this:
| ID | Address | Name | ID | Address | Name |
| 5 | 123 Pine St. | Alex Grey | 17 | 123 Pine St. | Alex Grey |