Some useful bits and pieces I've come across for using SQL, mostly the Teradata variant.
How to calculate a person's age correctly given a date and their date of birth in Teradata SQL.
Some useful SQL that lets you find how much disk space your database and tables are actually using.
Useful SQL to create a reference table of human generations like Millennial, Generation X, Baby Boomer etc with start and end dates.
This SQL lets you find all the tables in a particular database or your user area (your personal database) in Teradata, or table names that match a pattern.
How to compare two timestamps in SQL and express the result in hours.
How to find the number of AMPs and Nodes in a Teradata installation using a simple SQL query.
This SQL creates a series of commands that can be used to DROP (aka delete) all the TABLES that match a pattern or username.
Explains how to use SQL to check if a table already exists. Very useful to check prior to dropping a table, or for volatile tables if you re-run SQL.
This one came about because a set of data I was dealing with had UK postcodes in it. The data came in from a whole variety of sources, and as such, was not very good in quality terms. The system that the data was going to, on the other hand
OK, this one is fairly basic for anyone who regularly uses SQL, but it's a neat trick if you're not familiar with it. Normally when you create a table you have to specify all the fields and their formats in the CREATE statement. Then you populate it with an INSERT
If your reading a lot of records from a database and you need to find the first or last record in a sequence, you can do this in MS SQL by using TOP 1, or in MySQL by using LIMIT 1. QUALIFY OVER PARTITION But TOP and LIMIT don't exist