The intention here is to describe ANSI SQL, rather than vendor specific SQL.

You can use SQL Fiddle to try out SQL syntax, the site supports MySQL, Oracle, PostgreSQL, SQLite and MS SQL Server and hence serves as a useful test but there is nothing like a proper database.


If you want to understand what happens when the send a SQL query for execution then have a read of Life of a SQL query which gives a good overview.


A good visual starting point is Visual Representation of SQL Joins - CodeProject

Where Clause

It is easy to forget how "BETWEEN" works, so, for clarity it is this:

WHERE Length >= 5 AND Length <= 10
It is also worth noting that BETWEEN works with "WHERE" and "HAVING".

Tables Sizes

Sometimes I find it handy to get a count of the rows in a number of or all tables in a database. The following query gives a nice example of how this can be done:

SELECT 'people' AS "Table Name", COUNT(*) "Row Count" FROM people
SELECT 'desks' AS "Table Name", COUNT(*) "Row Count" FROM desks
SELECT 'offices' AS "Table Name", COUNT(*) "Row Count" FROM offices
SELECT 'companies' AS "Table Name", COUNT(*) "Row Count" FROM companies

The output will look something like this:

Table Name Row Count
people 323
desks 25
offices 3
companies 2

It is important to say that this is not necessarily the best way. For example with very large tables the query can take a long time to execute. Depending on which database software you are using there might be a better way, for example there may be a system schema for database information or statistics. The above works when you have basic query privileges but if you have a higher level of access then it will be better to study your database software for better options.