Tutorial by Examples

Table/Column Names Two common ways of formatting table/column names are CamelCase and snake_case: SELECT FirstName, LastName FROM Employees WHERE Salary > 500; SELECT first_name, last_name FROM employees WHERE salary > 500; Names should describe what is stored in their object. Th...
SELECT * returns all columns in the same order as they are defined in the table. When using SELECT *, the data returned by a query can change whenever the table definition changes. This increases the risk that different versions of your application or your database are incompatible with each other....
There is no widely accepted standard. What everyone agrees on is that squeezing everything into a single line is bad: SELECT d.Name, COUNT(*) AS Employees FROM Departments AS d JOIN Employees AS e ON d.ID = e.DepartmentID WHERE d.Name != 'HR' HAVING COUNT(*) > 10 ORDER BY COUNT(*) DESC; At th...
Explicit joins should always be used; implicit joins have several problems: The join condition is somewhere in the WHERE clause, mixed up with any other filter conditions. This makes it harder to see which tables are joined, and how. Due to the above, there is a higher risk of mistakes, an...

Page 1 of 1