views:

116

answers:

2

What are some useful SQL statements that should be known by all developers who may touch the Back end side of the project?

(Update: just like in algorithm, we know there are sorting problems, shuffling problems, and we know some solutions to them. This question is aiming at the same thing).

For example, one I can think of are:

Get a list of Classes that are not registered by any students. (Outer join and check whether the match is NULL, or by Get from Classes table, all ClassIDs which are NOT IN (a subquery to get all ClassIDs from the Registrations table))

Are there some SQL statements that should be under the sleeve of all developers that might touch back end data?

+6  A: 

Developers should learn the principles of databases and SQL. Not any specific SQL statements as SQL statements required will change depending on what the database stores and the structure of the database.

Update: Your updated question is interesting. I am thinking SQL statements in general are quite simple. So they are not worth memorising. If they are complex then they are tied to a specific problem and again are not worth memorising.

AJ Dhaliwal
Agreed. Understanding is always better than memorising.
armandino
But there are patterns of problems to solve that you should know how to handle, so that you can solve the specific problems.
HLGEM
@HLGEM But even in your answer below you did not mention patterns specific to SQL you mentioned queries that a reasonably proficient database developer should know. So are there patterns specific to SQL worth remembering? As I said it is an interesting question.
AJ Dhaliwal
I think I listed various types of query patterns not specific queries. If you know how to do type 10 on my list, then no matter what the database structure, you can create a set-based update.I think it was interesting enough, I'm writing up Wiki entries at a another site (http://lessthandot.com/) to discuss what a beginning dev should know to understand the query pattern. I'll update my answer later when they are done.
HLGEM
+5  A: 

Hmm generalizing what types of queries you should be able to write.

  1. First a straight up select with no
    joins (and no select *)
  2. You should know how to combine two or more tables and get records that are in all the tables
  3. You should know how to combine two or more tables and get records that are in all the tables but return only one record from the table with the many side of the one-to-many relationship
  4. You should be able to get the records in one table but not in an associated table
  5. You should be able to Aggregate data for a report
  6. You should be able to insert one record to a table
  7. You should be able to update one record in a table
  8. You should be able to delete one record in a table
  9. You should be able to insert a group of records to a table without a cursor
  10. You should be able to update a group of records in a table without a cursor
  11. You should be able to delete a group of records in a table without a cursor
  12. You should be able to perform multiple actions in one transaction and handle error trapping
  13. You should be able to create union of records and know when to use UNION vice UNION ALL
  14. You should be able to vary the data for one field based on some criteria (using CASE)
  15. You should be able to write an IF Statement.

Well that's what springs to mind immedaitely. This is for a beginner SQL developer of course. This includes nothing I would consider advanced.

HLGEM