What are some great SQL acronyms that you know about?
For example, for something that I learned today, you can specify a group by index:
SELECT col1, col2 FROM table GROUP BY 2
This will be the col2 group
See Aaron Bertrand's article βBad SQL Habits for a Hitβ - he has a message about this and strongly recommends not using this notation:
http://sqlblog.com/blogs/aaron_bertrand/archive/2009/10/06/bad-habits-to-kick-order-by-ordinal.aspx
Mark
- , SELECT, GROUP BY ORDER BY. , , , .
. IE:
SELECT FROM THIS_IS_MY_UNGODLY_TABLE_NAME timutn
... , timutn , , / , . , , ?
timutn
, , IDE- SQL intellisense , .
, WHERE 1=1
WHERE 1=1
,
$query = 'SELECT * FROM table '; <?php if ( $something ) { ?> $sql.= 'WHERE something = ' . $variable; <?php } else { ?> $sql.= 'WHERE something = ' . $another; <?php } ?>
If there are many branches there, it can be such a pain (and I do not believe in building query strings, but this is just an example).
A simple way:
$query = 'SELECT * FROM table WHERE 1=1 '; <?php if ( $something ) { ?> $sql.= 'AND something = ' . $variable; <?php } else { ?> $sql.= 'AND something = ' . $another; <?php } ?>
Of course, I would probably use a wrapper / class that has a method wherein which I can specify conditions.
where