When I make a SQL query, for example, in database where there’s a table named “employees”, which is the best practice of writing?
SELECT 'name', 'surname', 'phone' WHERE 'city'='ny' FROM 'employees' ORDER BY 'name'
SELECT name, surname, phone, WHERE city=ny FROM employees ORDER BY name
or
SELECT employees.name, employees.surname WHERE employees.city=ny ORDER BY employee.name
And why? Is there a standard for this?
IMHO, the best standard is this:
Your goal is improved clarity and maintenance. The features/benefits demonstrated here are:
employeenotemployees)id<table>_<column>my_table_name mtnGroup byandorder bypreferring numbers over expressions (if you change the expression, you don’t need to the group by or order by clauses, otherwise you’re violating the DRY principle)This comes from many years of coding SQL and I’ve found this makes things easiest.
If you always have a consistent format, you’ll find syntax errors easier to find too.