Checking in first draft of SQL code (untested)